For i = 0 To DataGridView1.Rows.Count - 1
            '  Dim row1 As Integer = DataGridView2.Rows(i).Cells(1).Value.ToString
            Dim row1 As Integer = Nothing
            Dim row2 As String = Nothing
            Dim row3 As String = Nothing
            Dim row4 As String = Nothing
            Dim row5 As String = Nothing
            Dim row6 As String = Nothing
            Dim row7 As String = Nothing
            Dim row8 As String = Nothing
            Dim row9 As String = Nothing
            Dim row10 As String = Nothing
            Dim row12 As String = Nothing
            Dim row11 As String = Nothing
            Dim row13 As String = Nothing
            Dim row14 As String = Nothing
            Dim row15 As String = Nothing
            Dim row16 As String = Nothing
            Dim row17 As String = Nothing
            IIf(IsNothing(DataGridView2.Rows(i).Cells(1).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(1).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(2).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(2).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(3).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(3).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(4).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(4).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(5).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(5).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(6).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(6).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(7).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(7).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(8).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(8).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(9).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(9).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(10).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(10).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(11).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(11).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(12).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(12).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(13).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(13).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(14).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(14).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(15).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(15).Value.ToString)
            IIf(IsNothing(DataGridView2.Rows(i).Cells(16).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(16).Value.ToString)
            ' IIf(IsNothing(DataGridView2.Rows(i).Cells(17).Value.ToString), String.Empty, DataGridView2.Rows(i).Cells(17).Value.ToString)
            Dim sqlquery As String = "INSERT INTO one(regno,rollno,nepali,com_english_w,com_english_o,com_math,social_w,social_o,science_w,science_o,hpe_w,hpe_o,creative,health,extra_math,extra_eng_w,extra_eng_o) values('" & row1 & "','" & row2 & "','" & row3 & "','" & row4 & "','" & row5 & "','" & row6 & "','" & row7 & "','" & row8 & "','" & row9 & "','" & row10 & "','" & row11 & "','" & row12 & "','" & row13 & "','" & row14 & "','" & row15 & "','" & row16 & "','" & row17 & "')"
            Dim sqlcommand As New OleDbCommand
            With sqlcommand
                .CommandText = sqlquery
                .Connection = conn
                .ExecuteNonQuery()      'Data type mismatch in criteria expression
            End With
        Next

i got error in this line.. plz help

my guess is that the data types in the database table are not the same as the types in your sqlstring. Are all the column data types in the table strings?

no.. i m using ms access and its all data type is number.. plz make it correct ..
thanx for help.

sir i coreected that and its solved now i got syntax error in
Dim sqlquery As String = "INSERT one(regno,rollno,nepali,com_english_w,com_english_o,com_math,social_w,social_o,science_w,science_o,hpe_w,hpe_o,creative,health,extra_math,extra_eng_w,extra_eng_o) values(" & row1 & "," & row2 & "," & row3 & "," & row4 & "," & row5 & "," & row6 & "," & row7 & "," & row8 & "," & row9 & "," & row10 & "," & row11 & "," & row12 & "," & row13 & "," & row14 & "," & row15 & "," & row16 & "," & row17 & ")"

       is there any syntax error. i cannot find any.. thanx for ur response.
        Dim sqlquery As String = "INSERT INTO one(regno,rollno,nepali,com_english_w,com_english_o,com_math,social_w,social_o," & _
           "science_w,science_o,hpe_w,hpe_o,creative,health,extra_math,extra_eng_w,extra_eng_o) values('" & row1 & "','" & _
            row2 & "','" & row3 & "','" & row4 & "','" & row5 & "','" & row6 & "','" & row7 & "','" & row8 & "','" _
             & row9 & "','" & row10 & "','" & row11 & "','" & row12 & "','" & row13 & "','" & row14 & "','" & row15 & "','" & row16 & "','" & row17 & "')"

I split the line up so that I could see all of it at the same time. This compiles ok with VB.NET 2012

Edited 3 Years Ago by Ancient Dragon

it gave me datatype mismatch error again. i wrote " & row1 & " instead of'" & row1 & "' but i didnt work..
n

This question has already been answered. Start a new discussion instead.