然后在Webform_ aspx cs里面获取连接字符串 要添加如下引用
复制代码 代码如下: using System Configurationusing System Datausing System Data SqlClient 复制代码 代码如下: SqlConnection conprotected void Page_Load(object sender EventArgs e) { ConnectDB()} private void ConnectDB() { string ConString = ConfigurationManager ConnectionStrings["ConnectionString"] ConnectionStringcon = new SqlConnection(ConString)con Open()SqlCommand = new SqlCommand()SqlDataReader sdrstring sqlstr = "select * from item"CommandText = sqlstrConnection = consdr = ExecuteReader()while (sdr Read()) { Response Write(sdr["字段名"] ToString()+"</br>")} sdr Close()sdr = null} lishixinzhi/Article/program/net/201311/14106SQL Server的连接方式
以本地服务器(LocalHost),数据库(Northwind)为例,可以有以下一些连接方式
SqlConnection conn=new SqlConnection( "Server=LocalHostIntegrated Security=SSPIDatabase=Northwind")
SqlConnection conn = new SqlConnection("Data Source=LocalHostIntegrated Security=SSPIInitial Catalog=Northwind")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)