如果要往数据库中插入一条记录(比如:"2005-05-21 7:09:34","关闭")如何做比较简单?

解决方案 »

  1.   

    如何做都不是很难。
    SqlConnection connection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["db"]);
    SqlCommand command=new SqlCommand();
    command.Connection=connection;
    command.CommandText="insert into table1(element1, element2) values('"+flag1+"','"+ flag2+"')";
    connection.Open();
    command.ExecuteNonQuery();
    connection.Close();
    command.Dispose();
      

  2.   

    我在Time字段中要插入当前时间,但写成
    command.CommandText = "INSERT INTO Log ([Time],Description) VALUES(strDT,'ddd')";
    后是不能执行的,其中strDT是时间变量,我用的是access数据库,这个问题怎么解决?