Search code examples
asp.netsql-servervb.netsqlparameterexecutenonquery

SQLServer INSERT getdate() function using parameters


What is the preferred method of adding the current date/time into an SQL Server table with INSERT Command and executenonquery? I'm expecting something like ...

        cmd.Parameters.Add("@theDate", SqlDbType.VarChar, 20)
        cmd.Parameters("@theDate").Value = "getdate()"

Solution

  • How about...

    cmd.Parameters.Add("@theDate", SqlDbType.DateTime)
    cmd.Parameters("@theDate").Value = DateTime.Now