使用C#编码的asp.net将数据插入Web应用程序的sql数据库中
问题描述:
我正在使用c#编码在asp.net中完成我的mca年度项目.这是基于Web的项目.实际上,我需要将数据插入数据库的编码.
i am doing my mca final year project in asp.net using c# coding. this is the web based project. actually i need the coding for inserting the data to database.
答
任何ADO.Net本书都可以告诉你.并且由于您正在执行MCA,所以我假设您有一个.因此,剩下的就是阅读它.
Any ADO.Net book would tell that. And since you are doing MCA, I assume you have one. So, only thing left is reading it.
请参阅下面的链接
http://msdn.microsoft.com/en-us/library/e80y5yhx(VS .71).aspx [ ^ ]
http://www.csharp-station.com/Tutorials/ADODotNet/Lesson01.aspx [ ^ ]
Refer the links below
http://msdn.microsoft.com/en-us/library/e80y5yhx(VS.71).aspx[^]
http://www.csharp-station.com/Tutorials/ADODotNet/Lesson01.aspx[^]
创建数据库,创建连接,然后在您的项目中使用此代码插入数据
Create database, create connection, and then use this code in your project to insert the data
<br />
string connStr = "Data Source=.;Initial Catalog=DatabaseName;Integrated Security=True";<br />
SqlConnection dbCon = new SqlConnection(connStr);<br />
SqlCommand sqlCmd;<br />
DataTable dbTbl;<br />
SQLCommand sqlCmd;<br />
sqlCmd = new SqlCommand();<br />
dbCon.Open();<br />
sqlCmd.CommandType = CommandType.StoredProcedure;<br />
sqlCmd.Connection = connStr ;<br />
sqlCmd.CommandText = ("INSERT INTO TABLE NAME VALUES(A,B,C) ");<br />
sqlCmd.ExecuteNonQuery()<br />
dbCon.Close();<br />
使用此代码,您将插入您的数据
use this code and u will get inserted your data