Question

There is this question here: insert datetime value in sql database with c# that works perfectly but I want to do something like this:

if(IsPostBack)
{
     for(int i = 0; i<100; i++)
     {
           commandText += string.Format( "insert into table (valuecoumn,datecolumn)" +
           "values({0},{1});" , 
           Request.Form["value-"+ i.ToString()],
           Request.Form["date-"+ i.ToString()]);

     }
     cmd.CommandText = commandText;
     cmd.ExecuteNonQuery();         
}

Now how should I deal with this as there are multiple date values?

Was it helpful?

Solution

Try putting single-quotes around the date-value in your format string

    '{1}'

See if that helps. In fact there is actually no problem quoting up all your values that way. SQL Server will un-quote anything it doesn't like quoted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top