Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I made a form application in visual studio which displays a patients vital sign levels for a hospital. I have created table in a Database in SQL to store that data in. What I want to know is how can I store that data displayed on my form in the tables i've made in SQL?
Posted

Remember don't forget to use namespace, Establish a connection to sql server, use SqlCommand. Paste these code into button_click event.
MIDL
SqlCommand cmd;
SqlConnection con = new SqlConnection("Data Source=.;initial catalog=YourDataBaseName;uid=sa;pwd=YourPasswordOfSqlserver");
con.Open();
cmd = new SqlCommand("insert EmployeeDetails values '"+
                      textBox1.Text+"',
                      '"+textBox2.Text+"',
                      '"+dateTimePicker1.Text+"',
                      '"+comboBox1.Text+"',
                      '"+textBox3.Text+"',
                      '"+textBox4.Text+"',
                      '"+textBox5.Text+"',
                      '"+textBox6.Text+"',
                      '"+maskedTextBox1.Text+"',
                      '"+dateTimePicker2.Text+"',
                      '"+comboBox2.Text+"',
                      '"+comboBox3.Text+"',
                      '"+textBox7.Text+"',
                      '"+maskedTextBox2.Text+"',
                      '"+textBox8.Text+"','NULL')", con);
cmd.ExecuteNonQuery();
con.Close();
 
Share this answer
 
v4
Comments
#realJSOP 20-Jan-11 13:58pm    
What is that?
Nish Nishant 20-Jan-11 14:02pm    
Whatever it is, it's not the best way to write to the DB :-)
fjdiewornncalwe 20-Jan-11 15:08pm    
Utter crap. Anyone who has actually taken 1 day of a course in sql would see what is wrong with this.

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