Sub loadtodgv()
        Dim sqlquery As String = "select * from nursery"
        Dim sqlcommand As New OleDbCommand
        Dim sqladapter As New OleDbDataAdapter
        Dim table As New DataTable
        With sqlcommand
            .CommandText = sqlquery
            .Connection = conn
            .ExecuteNonQuery()

        End With
        With sqladapter
            .SelectCommand = sqlcommand
            .Fill(table)

        End With
        DataGridView1.Rows.Clear()

        For i = 0 To table.Rows.Count - 1
            With DataGridView1
                .Rows.Add(table.Rows(i)("regno"), table.Rows(i)("rollno"), table.Rows(i)("nepali(writing)"), table.Rows(i)("nepali(oral)"), table.Rows(i)("maths(writing1)"), table.Rows(i)("maths(oral)"), table.Rows(i)("maths(writing2)"), table.Rows(i)("english(writing)"), table.Rows(i)("english(oral)"), table.Rows(i)("physical_edu(oral)"), table.Rows(i)("creative(oral)"))
            End With
        Next
    End Sub

    Private Sub btndel_nursery_Click(sender As Object, e As EventArgs) Handles btndel_nursery.Click
        For i = 0 To DataGridView1.Rows.Count - 1
            Dim deleterows As String = DataGridView1.SelectedRows(i).Cells(0).Value.ToString
            Dim sqlquery As String = "delete from nursery where regno=" & deleterows & ""
            Dim sqlcommand As New OleDbCommand
            With sqlcommand
                .CommandText = sqlquery
                .Connection = conn
                .ExecuteNonQuery()

            End With
        Next
        loadtodgv()
    End Sub
End Class

why these error comes to my code. plz help..
.executenonquery() ' no value given for one or more parameter

It didnot worked after putting .executereader... same error occurs

Can't you get any information in debugmode? What parameter is missing? Try to find an ADO.Net example, read some ADO.Net documentation; maybe you can find some clues for use. The way you use it, is somewhat compact. Usually it is spread over some layers of code. Good luck

In line 28, why use SelectedRows property? Perhaps after a time, there is no selectedrow, therefore giving no value to the regno parameter?

thanx scudzilla for response.. its because i want to delete selected rows from datagrid.. if its not correct plz provide me correct code..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.