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

Dani AI

Generated

Short version: the error is caused by malformed SQL/parameters and a problematic loop — not by ExecuteReader vs ExecuteNonQuery. The Jet/ACE message "No value given for one or more required parameters" means the engine found an identifier it does not recognize (often an unquoted string or a bad column name). you are calling ExecuteNonQuery on a SELECT (unnecessary) and building DELETE SQL by concatenation while iterating SelectedRows with the wrong index. was right that a reader is used for SELECTs, but the real fixes are: stop executing the SELECT manually, quote or (better) parameterize the DELETE, and iterate the SelectedRows collection correctly (as suspected).

Common causes and how to fix them

  • If regno is text and you build DELETE FROM nursery WHERE regno=abc (no quotes), Access treats abc as a parameter and throws that error. Always parameterize or quote values.
  • Fields or table names that contain spaces or punctuation (for example names with parentheses) must be delimited with square brackets in SQL: [nepali(writing)].
  • Don’t call .ExecuteNonQuery() on a SELECT; use OleDbDataAdapter.Fill or ExecuteReader for SELECTs.

Safe patterns (VB.NET examples)

Parameterized delete over selected rows:

If DataGridView1.SelectedRows.Count = 0 Then Return

Using cmd As New OleDbCommand("DELETE FROM nursery WHERE regno = ?", conn)
    cmd.Parameters.Add("@p1", OleDbType.Integer) ' use appropriate OleDbType
    If conn.State <> ConnectionState.Open Then conn.Open()
    For Each r As DataGridViewRow In DataGridView1.SelectedRows
        Dim val = r.Cells("regno").Value
        If val Is Nothing Then Continue For
        cmd.Parameters(0).Value = Convert.ToInt32(val) ' or CStr(val) if text
        cmd.ExecuteNonQuery()
    Next
End Using

loadtodgv()

Select/fill pattern (avoid ExecuteNonQuery):

Dim dt As New DataTable()
Using da As New OleDbDataAdapter("SELECT [regno],[rollno] FROM [nursery]", conn)
    da.Fill(dt)
End Using
DataGridView1.DataSource = dt

Troubleshooting tips

  • Debug.Print or log the final SQL when you build it (if you concatenate) to see missing quotes.
  • Wrap DB calls in Try/Catch and show ex.Message and ex.ErrorCode.
  • Prefer parameterized commands (protects from type errors and SQL injection).

Applying these changes will remove the parameter error and make deletes reliable when multiple rows are selected.

Recommended Answers

All 6 Replies

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.