2、打开连接到数据库提供方终结点的应用程序的应用程序配置文件即可。
复制代码 代码如下: <connectionStrings><add name=ConnectionString connectionString="user id=用户名password=密码initial catalog=数据库名称data source=服务器名称"/></connectionStrings>然后在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/14106
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)