(配置文件)
<connectionStrings>
<add name="Conn" connectionString="Data Source=192.168.1.109;Initial Catalog=GuoHong;Persist Security Info=True;User ID=sa password=123"/>
</connectionStrings>
--------------------------------------------------
(DBHelper)
public class DBHelper
{
public static string Conn = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
public static DataTable ExecuteDataTable(string sql,params SqlParameter[] para)
{
using(SqlConnection conn=new SqlConnection(Conn))
{
conn.Open();
using(SqlCommand cmd=conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddRange(para);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds);
return ds.Tables[0];
}
}
}
}
-----------------------------------
(Default.aspx.cs)
protected void Page_Load(object sender, EventArgs e)