APP.config配置如下:
主要是数据库操作:
方法一: string _connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["strCon"].ToString();
方法二: string _connectionString = ConfigurationManager.AppSettings["ConnectionString"];
在后台读取:
SqlConnection conn = new
SqlConnection();
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["strCon"].ConnectionString;
conn.Open();
string sql = "select * from
Orders";
SqlCommand cmd = new SqlCommand(sql,
conn);
SqlDataAdapter da = new
SqlDataAdapter();
da.SelectCommand =
cmd;
DataSet ds = new
DataSet();
da.Fill(ds);
this.dataGridView1.DataSource =
ds.Tables[0];
conn.Close();