这是场景:
我需要在我的数据库中插入一些行,其中一列是 DateTime 类型,它具有 SysDateTime 作为值,通常我的查询看起来像这样
String sqlString = "INSERT INTO Temas(Id, Level,Date, Description) " +
" VALUES (100, 3, SYSDATETIME() , 'Text ')";
现在我必须使用参数进行插入,现在它看起来像这样:
private void InsertTemaInTesauro(OleDbDataReader origenReader,Materias materia)
{
SqlConnection connectionEpsOle = Conexiones.GetConecction();
SqlDataAdapter dataAdapter;
DataSet dataSet = new DataSet();
DataRow dr;
string sqlCadena = "SELECT * FROM Temas WHERE idTema = 0";
dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = new SqlCommand(sqlCadena, connectionEpsOle);
dataAdapter.Fill(dataSet, "Temas");
dr = dataSet.Tables["Temas"].NewRow();
dr["Id"] = 100;
dr["Level"] = 3;
dr["Date"] = ????;
dr["Description"] = 'Some text';
dataSet.Tables["Temas"].Rows.Add(dr);
//dataAdapter.UpdateCommand = connectionEpsOle.CreateCommand();
dataAdapter.InsertCommand = connectionEpsOle.CreateCommand();
dataAdapter.InsertCommand.CommandText =
"INSERT INTO Temas(Id,Level,Date,Description) (@Id,@Level,@Date,@Description)";
dataAdapter.InsertCommand.Parameters.Add("@Id", SqlDbType.Numeric, 0, "Id");
dataAdapter.InsertCommand.Parameters.Add("@Level", SqlDbType.Numeric, 0, "Level");
dataAdapter.InsertCommand.Parameters.Add("@Date", SqlDbType.DateTime, 0, "Date");
dataAdapter.InsertCommand.Parameters.Add("@Description", SqlDbType.Numeric, 0, "Description");
dataAdapter.Update(dataSet, "Temas");
dataSet.Dispose();
dataAdapter.Dispose();
connectionEpsOle.Close();
}
我的问题是如何设置日期参数以获取 sysdatetime() 的值,我无法将其设置为列的默认值,因为我无权访问数据库,也无法使用 DateTime.Now,因为老板要数据库的时间