在WebConfig中配置數據庫連接字符串
<connectionStrings>
<add name="ConnectionString" connectionString="user id=用戶名;password=密碼;initial catalog=數據庫名稱;data source=服務器名稱"/>
</connectionStrings>
然後在Webform_
using System
using System
using System
代碼
SqlConnection con;
protected void Page_Load(object sender
{
ConnectDB();
}
private void ConnectDB()
{
string ConString = ConfigurationManager
con = new SqlConnection(ConString);
con
SqlCommand com = new SqlCommand();
SqlDataReader sdr;
string sqlstr = "select * from item";
com
com
sdr = com
while (sdr
{
Response
}
sdr
sdr = null;
}
From:http://tw.wingwit.com/Article/program/net/201311/14106.html