.net读取mssql基础语句– 使用web.config保存数据库字符串

分类: c# | 标签: | 日期:2009-10-26

web.config 中 加入




Connect Timeout=300 是连接超时时间!

程序中读取:

using System.Configuration;
using System.Data.SqlClient;

SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["datastr"]);

SqlCommand cmd = new SqlCommand(“sql语句”, con);

con.Open();

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())

{

dr[“数据库中表的字段名”].ToString();

}

dr.Close();//关闭

con.Close();

只能读取~ 搞定!

表情:<( ̄︶ ̄)> | (⊙ˍ⊙) | >﹏< | b( ̄▽ ̄)d | (─.─||) | (^_-)

[ Ctrl+Enter提交 ]