Select_query[Fetching data to textbox]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class Registration : System.Web.UI.Page
{
SqlConnection cn;
SqlCommand cm;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{ //step 1- connection to database
string path =@"Data Source=49.50.88.43;Initial Catalog=grkistdb;Persist Security Info=True;User ID=grkistuser;Password=q2oR5w_356"
cn = new SqlConnection(path);
cn.Open();
//step 2- Command (write a query)
string q = " select * from Chitransh_stu where roll= '"+TextBox1.Text+"'";
cm = new SqlCommand(q, cn);
//step 3- execute the query
dr= cm.ExecuteReader();
if(dr.Read())
{
TextBox3.Text = dr["name"].ToString();
TextBox4.Text = dr["mobile"].ToString();
TextBox5.Text = dr["sub"].ToString();
TextBox6.Text = dr["pass"].ToString();
TextBox7.Text = dr["age"].ToString();
}
else
{
dr.Close();
Response.Write("Records not found");
}
}
}
Comments
Post a Comment