Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello every1,I have a form in visual c# which contain 12 textboxes,2 comboboxes,1 richtextbox,&3 checkboxes,some one plz help me
1. how to retrieve data for combobox from database?
2. how to show the checkbox values in database?

For inserting the values in textbox to database, here is my code:-


private void btnsave_Click(object sender, EventArgs e)
{
SqlConnection sc = new SqlConnection("Data Source=Marvella-1240\\SQLEXPRESS;Initial Catalog=Customer;Integrated Security=True");
SqlCommand cmd;
{
try
{
sc.Open();
cmd = new SqlCommand("insert into [dbo].[CustomerValidationtext] values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "','" + textBox11.Text + "','" + textBox12.Text + "')", sc);

cmd.ExecuteNonQuery();
MessageBox.Show("save to Db");
sc.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Posted
Updated 29-Jul-13 19:15pm
v4
Comments
[no name] 29-Jul-13 6:49am    
Help you with what exactly? Connect to your database, query the data you want, disconnect from your database, do whatever you want with the data.
Prasad Khandekar 29-Jul-13 9:14am    
Hello Marvella,

You may want to look at this thread. (http://www.codeproject.com/Questions/243493/Sample-Code-Csharp-Database-Application-Windows-Fo) Or this (http://msdn.microsoft.com/en-us/library/aa984466(v=vs.71).aspx) or this (http://msdn.microsoft.com/en-us/library/aa984462(v=vs.71).aspx).

Regards,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900