开发者

How to connect to SQL Server with asp.net

I want to connect to SQL Server with ASP.NET. Can a开发者_开发百科ny 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

Good Luck!


June R's example is inserting data.

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜