Jump to content
ChetanaSforum
rboogi

how to retrive and post data to the database

Recommended Posts

hai friends pls tell me hoe to get data from DB i know to create form and database connection but i dont know how to get a data..........................

Share this post


Link to post
Share on other sites

hai friends pls tell me hoe to get data from DB i know to create form and database connection but i dont know how to get a data..........................

Hi friend..just give this code a try..the table name is customer..here wen u give the customer name in one text box u will get the corresponding cid,address etc in the corresponding text boxes con.Open(); str = "Select * from customer where(cname='" + textBox1.Text + "')"; cmd = new SqlCommand(str, con); dr = cmd.ExecuteReader(); if(dr.HasRows) { while (dr.Read()) { textBox2.Text = dr["cid&quot].ToString(); textBox3.Text = dr["address&quot].ToString(); textBox4.Text = dr["landline&quot].ToString(); textBox5.Text = dr["mobile&quot].ToString(); textBox6.Text = dr["email&quot].ToString();}con.close();dr.close();}

Share this post


Link to post
Share on other sites

Hi friend..just give this code a try..the table name is customer..here wen u give the customer name in one text box u will get the corresponding cid,address etc in the corresponding text boxes con.Open(); str = "Select * from customer where cname= @custname"; cmd = new SqlCommand(str, con); cmd.Paramaters.Add(new SqlParameter("@custname" + textBox1.Text)); // make it a habit to use above command as its more secure than the one in prev post. dr = cmd.ExecuteReader(); if(dr.HasRows) { while (dr.Read()) { textBox2.Text = dr["cid&quot].ToString(); textBox3.Text = dr["address&quot].ToString(); textBox4.Text = dr["landline&quot].ToString(); textBox5.Text = dr["mobile&quot].ToString(); textBox6.Text = dr["email&quot].ToString(); } }dr.close();con.close();}

just made some changes to the above code...

Share this post


Link to post
Share on other sites

Hey...Its a nice information that you have shared here..I am much happy to see all of these coding because this can be helpful to me for further posting...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×