Hi Indradeo,
Please refer below sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
Default
<table>
<tr>
<td>
<asp:TextBox ID="txtId" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="Submit" /></td>
</tr>
</table>
Home
<table>
<tr>
<td>Id:
<asp:Label ID="lblMobileNo" runat="server"></asp:Label></td>
</tr>
<tr>
<td>Phone:
<asp:Label ID="lblMessage" runat="server"></asp:Label></td>
</tr>
</table>
Namespaces
C#
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
Default
protected void Submit(object sender, EventArgs e)
{
Response.Redirect("Home.aspx?EmpId=" + txtId.Text.Trim());
}
Home
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
lblMobileNo.Text = Request.QueryString["EmpId"];
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT HomePhone FROM Employees WHERE EmployeeId=@Id", con))
{
cmd.Parameters.AddWithValue("@Id", lblMobileNo.Text);
con.Open();
lblMessage.Text = Convert.ToString(cmd.ExecuteScalar());
con.Close();
}
}
}
}
VB.Net
Default
Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("Home.aspx?EmpId=" & txtId.Text.Trim())
End Sub
Home
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
lblMobileNo.Text = Request.QueryString("EmpId")
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("SELECT HomePhone FROM Employees WHERE EmployeeId=@Id", con)
cmd.Parameters.AddWithValue("@Id", lblMobileNo.Text)
con.Open()
lblMessage.Text = Convert.ToString(cmd.ExecuteScalar())
con.Close()
End Using
End Using
End If
End Sub
Screenshot