Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top