I want to insert the data from a GridView into SQL table. I have this code
foreach (GridViewRow GVRow in GridView2.Rows)
{
string ID = GVRow.Cells[1].Text;
string DateTim = GVRow.Cells[2].Text;
string Location = GVRow.Cells[3].Text;
string IncidentType = GVRow.Cells[4].Text;
string Direction = GVRow.Cells[5].Text;
string LaneBlockage = GVRow.Cells[6].Text;
string CCTV = GVRow.Cells[7].Text;
string SignalTimingChanges = GVRow.Cells[8].Text;
string Benefits = GVRow.Cells[9].Text;
string Latitude = GVRow.Cells[10].Text;
string Longitude = GVRow.Cells[11].Text;
conn = new SqlConnection("Data Source=...;Initial Catalog=incidents;Persist Security Info=True;User ID=...;Password=...");
SqlConnection scn = new SqlConnection(clspublic.GetConnectionString());
using (conn)
{
SqlCommand scm = new SqlCommand();
scm.Connection = conn;
scm.CommandText = @"insert into TrafInc1 (ID, DateTim, Location, IncidentType, Direction, LaneBlockage,CCTV, SignalTimingChanges, Benefits, Latitude, Longitude)
VALUES (@ID,@DateTime,@Location,@IncidentType,@Direction,@LaneBlockage,@CCTV,@SignalTimingChanges,@Benefits,@Latitude,@Longitude)";
scm.Parameters.AddWithValue("@ID", ID.ToString());
scm.Parameters.AddWithValue("@DateTime", DateTim);
scm.Parameters.AddWithValue("@Location", Location);
scm.Parameters.AddWithValue("@IncidentType", IncidentType);
scm.Parameters.AddWithValue("@Direction", Direction);
scm.Parameters.AddWithValue("@LaneBlockage", LaneBlockage);
scm.Parameters.AddWithValue("@CCTV", CCTV);
scm.Parameters.AddWithValue("@SignalTimingChanges", SignalTimingChanges);
scm.Parameters.AddWithValue("@Benefits", Benefits);
scm.Parameters.AddWithValue("@Latitude", Latitude.ToString());
scm.Parameters.AddWithValue("@Longitude", Longitude.ToString());
scm.ExecuteNonQuery();
}
}
but when I run it I get this error