Note that there are some explanatory texts on larger screens.

plurals
  1. POSysDateTime() on Insert Query as parameter
    text
    copied!<p>This is the scenario:</p> <p>I need to insert some rows on my database, one of the columns is DateTime type, which has SysDateTime as Value, usually my query looks like this</p> <pre><code>String sqlString = "INSERT INTO Temas(Id, Level,Date, Description) " + " VALUES (100, 3, SYSDATETIME() , 'Text ')"; </code></pre> <p>Now i have to make the insert using parameters, now it looks like this:</p> <pre><code>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(); } </code></pre> <p>My question is how to set the parameter of date to take the value of sysdatetime(), i can´t set it as the default value of the column because i have no access to the database and i can´t use DateTime.Now because the boss wants the time of the database</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload