0

I am getting above error while i am trying to save the grid view data.Here is my code.I want to skip this error for Debit and Credit Column.Please Help me out,Here is my code:

For i As Integer = 0 To DataGridView1.Rows.Count - 2 Step +1
        cmd = New SqlCommand("INSERT INTO JVDetails (JVNo, Date, AccountNo, AccountName, Description, Debit, Credit) VALUES (@JVNo, @Date, @AccountNo, @AccountName, @Description, @Debit, @Credit)", con)
        cmd.Parameters.AddWithValue("@JVNo", txt_JVno.Text)
        cmd.Parameters.AddWithValue("@Date", txt_date.Text)
        cmd.Parameters.Add("@AccountNo", SqlDbType.NVarChar).Value = DataGridView1.Rows(i).Cells(0).Value.ToString()
        cmd.Parameters.Add("@AccountName", SqlDbType.NVarChar).Value = DataGridView1.Rows(i).Cells(1).Value.ToString()
        cmd.Parameters.Add("@Description", SqlDbType.NVarChar).Value = DataGridView1.Rows(i).Cells(2).Value.ToString()
        cmd.Parameters.Add("@Debit", SqlDbType.Float).Value = DataGridView1.Rows(i).Cells(3).Value.ToString()
        cmd.Parameters.Add("@Credit", SqlDbType.Float).Value = DataGridView1.Rows(i).Cells(4).Value.ToString()
        cmd.ExecuteNonQuery()
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • There's no such thing as VBA.NET. Also, don't specify the language in the title. That's what tags are for. If you feel that you have to add the language to make your title unique then you almost certainly have a bad title, as is the case here. – jmcilhinney Aug 15 '20 at 06:54
  • You should mot be looping through a `DataGridView` and calling `ExecuteNonQuery`. Create a `DataTable` and bind it to the grid, then save the lot with a single call to `Update` on a data adapter. – jmcilhinney Aug 15 '20 at 06:56
  • Hi, Sir should i need to make any changes too in my save button code.Please advice – sarfaraj Alam Aug 17 '20 at 09:27

0 Answers0