Hi indradeo,
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox ID="txtName" runat="server" />
<asp:LinkButton Text="Redirect" runat="server" OnClick="Save" />
Code
Default
C#
protected void Save(object sender, EventArgs e)
{
Response.Redirect("Home.aspx?Name=" + txtName.Text.Trim());
}
VB.Net
Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("Home.aspx?Name=" & txtName.Text.Trim())
End Sub
Home
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string name = Request.QueryString["Name"];
if (!string.IsNullOrEmpty(name))
{
string query = "INSERT INTO Details VALUES(@Name)";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@Name", name);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim name As String = Request.QueryString("Name")
If Not String.IsNullOrEmpty(name) Then
Dim query As String = "INSERT INTO Details VALUES(@Name)"
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand(query)
cmd.Parameters.AddWithValue("@Name", name)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End If
End If
End Sub