0

Hi I'm having trouble with updating one of my tables using vb.net when i click on the button to update the data base it give me the error "System.Data.OleDb.OleDbException: No value given for one or more required parameters." here is the code

Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
    Dim aConnection As New OleDbConnection
    Dim aCommand As New OleDbCommand
    Dim SQLQuery, aConnectionString As String
    Dim Text As String = TextBox1.Text
    Dim aDataAdapter As New OleDbDataAdapter
    Dim aDataReader As New DataSet
    SQLQuery = "Update Review Set report='Yes' Where Text='" & Text & "'"
    aConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Server.MapPath("App_Data/BookReviewWebsite.accdb")
    aConnection = New OleDbConnection(aConnectionString)
    aConnection.Open()

    aCommand = New OleDbCommand(SQLQuery, aConnection)

    aCommand.ExecuteNonQuery()


    Label15.Text = "Review has been reported"

    aConnection.Close()

End Sub
jonathan
  • 15
  • 1
  • 7

1 Answers1

0

Review, Report and Text. Here you have two fields and a table name, you should check if your database effectively contains a table named Review and if, in this table, there are two field named report and Text.

If your really have this table and these fields, then you need to enclose the word TEXT with square brackets because the word TEXT is a reserved keyword in Access 2007.

Last, but not least of your problems is the query string itself. Concatenating strings in that way could be a source of errors. If you have a single quote in your 'Text' variable then the results could be impredictable and range from Syntax error to Sql Injection

SQLQuery = "Update Review Set report='Yes' Where [Text]=?"
aCommand = New OleDbCommand(SQLQuery, aConnection)
aCommand.Parameter.AddWithValue("@p1", Text)
aCommand.ExecuteNonQuery()
Community
  • 1
  • 1
Steve
  • 213,761
  • 22
  • 232
  • 286