[英]How to connect to SQL Server with asp.net
I want to connect to SQL Server with ASP.NET. 我想使用ASP.NET连接到SQL Server。 Can any one give me some sample program to do so?
有人可以给我一些示例程序吗?
Here's an example 这是一个例子
http://www.beansoftware.com/ASP.NET-Tutorials/ASP.NET-SQL-Server.aspx http://www.beansoftware.com/ASP.NET-Tutorials/ASP.NET-SQL-Server.aspx
Good Luck! 祝好运!
June R's example is inserting data. June R的示例是插入数据。
using System.Data;
using System.Data.SqlClient;
string Connection = "server=ALDAN; uid=sa; pwd=sa; database=GAZCAD; Connect Timeout=10000";
SqlConnection DataConnection = new SqlConnection(Connection);
// the string with T-SQL statement, pay attention: no semicolon at the end of //the statement
string Command = "Select * from myTable";
// create the SQLCommand instance
SQLCommand DataCommand = new SqlCommand(Command, DataConnection);
// open the connection with our database
DataCommand.Connection.Open();
// Data adapter
SqlDataAdapter da = new SqlDataAdapter(DataCommand);
// To fill data, i need a datatable.
DataTable dt = new DataTable();
// Filling my table
da.Fill(dt);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.