本帖最后由 苏波 于 2013-3-8 20:51 编辑
<configuration>
<connectionString>
<add name="dbConnStr" connectionString="Data Source=.;Initial Catalog=MyTest;User ID=sa;Password=123456"/>
</connectionString>
配置文件
下面的是SqlHelper代码
class SqlHelper
{
private static string connStr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
public static int ExecuteNonQuery(string sql)
{
using (SqlConnection conn=new SqlConnection (connStr))
{
conn.Open();
using (SqlCommand cmd=conn.CreateCommand ())
{
cmd.CommandText = sql;
return cmd.ExecuteNonQuery();
}
}
}
public static object ExecuteScalar(string sql)
{
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
return cmd.ExecuteScalar();
}
}
}
}
帮忙看下 有什么问题 求解答 |
|