Sunday, 11 August 2013
How to read Multiple Values From Table using single SqlCommand and Display values in Label
Hi friends today i shows How to read Multiple Values From Table using single SqlCommand and
Display values in Label using SqlDataReader . Simple way to export grid view into excel . How to read a data from database and display in a Label. are our previous posts .
Table values:
Table values:
.Aspx page
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=JISHNU\\SQLEXPRESS;Initial Catalog=dreamtheweb;Integrated Security=True");
String str = "SELECT [name], [email], [phone] FROM [account] WHERE ([id] = 1)";
SqlCommand cmd = new SqlCommand(str, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Label1.Text = dr["name"].ToString();
Label2.Text = dr["email"].ToString();
Label3.Text = dr["phone"].ToString();
}
con.Close();
}
.CS page:
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
</div>
</form>
Result
Read our next post
0 comments:
Post a Comment