如何使用C#程序将数据存储在SQL数据库中? [英] How can I can store data in a SQL database using my c# program?
本文介绍了如何使用C#程序将数据存储在SQL数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我在Visual Studio中创建了一个表单应用程序,用于显示患者医院的生命体征水平.我已经在SQL中的数据库中创建了表以存储该数据.我想知道如何将在窗体上显示的数据存储在用SQL创建的表中?
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?
推荐答案
以下是一些链接:
http://msdn.microsoft.com/en-us/library/system. data.sqlclient.sqlconnection.aspx [ ^ ]
通过C#访问SQL Server的入门指南 [ http://www.csharphelp.com/2006/02/accessing-data-from -sql-server/ [ ^ ]
http://www.dreamincode.net/forums/topic/31314-sql -basics-in-c%23/ [
Here are some links:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx[^]
Beginners guide to accessing SQL Server through C#[^]
http://www.csharphelp.com/2006/02/accessing-data-from-sql-server/[^]
http://www.dreamincode.net/forums/topic/31314-sql-basics-in-c%23/[^]
记住不要忘记使用命名空间,建立与sql server的连接,使用SqlCommand.将这些代码粘贴到button_click事件中.
Remember don''t forget to use namespace, Establish a connection to sql server, use SqlCommand. Paste these code into button_click event.
<pre lang="midl"><br />
SqlCommand cmd;<br />
SqlConnection con = new SqlConnection("Data Source=.;initial catalog=YourDataBaseName;uid=sa;pwd=YourPasswordOfSqlserver");<br />
con.Open();<br />
cmd = new SqlCommand("insert EmployeeDetails values ''"+<br />
textBox1.Text+"'',<br />
''"+textBox2.Text+"'',<br />
''"+dateTimePicker1.Text+"'',<br />
''"+comboBox1.Text+"'',<br />
''"+textBox3.Text+"'',<br />
''"+textBox4.Text+"'',<br />
''"+textBox5.Text+"'',<br />
''"+textBox6.Text+"'',<br />
''"+maskedTextBox1.Text+"'',<br />
''"+dateTimePicker2.Text+"'',<br />
''"+comboBox2.Text+"'',<br />
''"+comboBox3.Text+"'',<br />
''"+textBox7.Text+"'',<br />
''"+maskedTextBox2.Text+"'',<br />
''"+textBox8.Text+"'',''NULL'')", con);<br />
cmd.ExecuteNonQuery();<br />
con.Close();</pre><br />
这篇关于如何使用C#程序将数据存储在SQL数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文