previous....
Next..
Here i will explain that when i select any name from combobox then is all detail show in respective textboxes.
Step(1):-Form with combobox
drag and down a combobx from toolbox.
Step(2):-Coding
Click on combobox and write this coding.
Private Void comboBox1.SelectedIndexChanged(object sender , EventArgs e)
{
string str = "server = MUNESH\\SQL2008R2;Database=datastore;UID=sa;Password=123;";
SqlConnection con = new SqlConnection(str);
string query = "select * from tablename where name = '"+combobox1.text+"' ";
SqlCommand cmd = new SqlCommand( query,con);
sqldatareader dbr;
try
{
con.open();
dbr = cmd.executereader();
while(dbr.read())
{
string sID = (string) dbr["ID"].tostring;
string sname = (string) dbr["name"] // name is string value
string ssurname = (string) dbr["surname"]
string sage = (string) dbr["age"].tostring;
textbox1.text = sid;
textbox2.text = sname;
textbox3.text = ssurname ;
textbox4.text = sage;
}
catch(execption es)
{
messagebox.show(es.message);
}
}
}
Step(3):-OutputRun your application and click on name which is in combobox.
Next..
can i retrieve data from sql database to textboxes in windows form?
ReplyDeleteYes you can do this also..
ReplyDeleteSqlConnection con = new SqlConnection("server=Munesh-PC; database=Temp; uid= sa;pwd=***");
SqlDataReader dr;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
string GetData = "Select * from TempTable where ID= 1";
cmd = new SqlCommand(GetData, con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
TextBox1.Text = dr[0].ToString();
TextBox2.Text = dr[1].ToString();
}
Are you in Australia? if so are you in Sydney? i am looking for a tutor for visual C#
ReplyDeleteare you in Australia? if so are you in Sydney? i am looking for a visual studio c# tutor.
ReplyDeletehow can i get data in textboxes from database if my combobox selected values are from table1 and the values i want to get in textboxes are from table2?
ReplyDelete