Tuesday, 10 September 2013

I have a datagridview and want to save data from it to sqlserver in vb.net here is my code

I have a datagridview and want to save data from it to sqlserver in vb.net
here is my code

In the following code, dgv is a DataGridView:
c =dgv.Rows.Count
For i = 0 To c - 1
cmd.CommandText = "INSERT INTO " & myfile & " (id,name) VALUES (@a1,@a2)"
cmd.Parameters.AddWithValue("@a1", dgv.Rows(i).Cells(0).Value.ToString())
cmd.Parameters.AddWithValue("@a2", dgv.Rows(i).Cells(1).Value.ToString())
Next
The data is not saving in to the database. There is no error. What am I
doing wrong?

No comments:

Post a Comment