复制代码 代码如下:
<connectionStrings>
<add connectionString="user id=用户名;password=密码;initial catalog=数据库名称;data source=服务器名称"/>
</connectionStrings>
复制代码 代码如下:
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
复制代码 代码如下:
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
ConnectDB();
}
private void ConnectDB()
{
string ConString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
con = new SqlConnection(ConString);
con.Open();
SqlCommand com = new SqlCommand();
SqlDataReader sdr;
string sqlstr = "select * from item";
com.CommandText = sqlstr;
com.Connection = con;
sdr = com.ExecuteReader();
while (sdr.Read())
{
Response.Write(sdr["字段名"].ToString()+"</br>");
}
sdr.Close();
sdr = null;
}
新闻热点
疑难解答
图片精选