增
using (SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["DGE_DBConn"]))
{
cn.Open();
// 括号中的Date换城 @GETDATE() 可直接对数据库存储现在的时间
string sql = "INSERT INTO [Demo1](Date, Matter, MainContent, Supervision, result) VALUES (@Date, @Matter, @MainContent, @Supervision, @result)";
SqlCommand cm = new SqlCommand(sql, cn);
cm.Parameters.Add("@Date", SqlDbType.DateTime);
cm.Parameters.Add("@Matter", SqlDbType.NVarChar);
cm.Parameters.Add("@MainContent", SqlDbType.NVarChar);
cm.Parameters.Add("@Supervision", SqlDbType.NVarChar);
cm.Parameters.Add("@result", SqlDbType.NVarChar);
//强制转换Convert.ToDateTime(TextBox1.Text.Trim().ToString());
//DateTime.Now(现在的时间)
cm.Parameters["@Date"].Value = (new DateTime(2016, 1, 1));
cm.Parameters["@Matter"].Value = "1月6日中交城投城综事业部领导莅临总项目部调研";
cm.Parameters["@MainContent"].Value = "对全线现场施工安全质量及内业资料进行检查";
cm.Parameters["@Supervision"].Value = "开工条件及施工日常管理";
cm.Parameters["@result"].Value = "生产符合“常态化”";
cm.ExecuteNonQuery();
cn.Close();
}
查
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["NMXT_DBConn"].ConnectionString))
{
string sql = "SELECT * FROM [Demo1] WHERE Id = 2";
SqlDataAdapter da = new SqlDataAdapter(sql, cn);
DataSet ds = new DataSet();
da.Fill(ds);
Session["DebugView"] = ds;
}