Results 1 to 6 of 6
  1. #1
    christing is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    10

    Get error on No value given for one or more required parameters.

    cmd.Connection = app
    If CStr(Textbox1.Tag) & "" = "" Then
    cmd.CommandText = "INSERT INTO ADMIN(CusID,Name) " & _
    " VALUES('" & Me.Textbox1.Text & "','" & Me.txtname.Text & "')"


    cmd.ExecuteNonQuery()


    Else

    cmd.CommandText = "UPDATE ADMIN " & _
    " SET ID=" & Me.Textbox1.Text & _
    ",Name='" & Me.txtname.Text & "'" & _
    "WHERE ID=" & CStr(Textbox1.Tag)
    cmd.ExecuteNonQuery() (Get error on No value given for one or more required parameters.)

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Is this code in the same db as tables to be edited? If so, don't need connection and command objects.

    Don't use Text property. You want Value property and since it is default don't even have to type it.

    CurrentDb.Execute "INSERT …"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    christing is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    10
    yes it is a same data table. but normally insert data is use this command to add data. i am success add data delete data exclude update data. and fail on this command cmd.ExecuteNonQuery() (Get error on No value given for one or more required parameters.)
    which mean i need change my cmd.CommandText = "INSERT INTO ADMIN(CusID,Name) " & _

    If Me.dgv.Rows.Count > 0 Then
    If Me.dgv.SelectedRows.Count > 0 Then
    Dim intID As Integer = CInt(Me.dgv.SelectedRows(0).Cells("ID").Value)
    If Not app.State = ConnectionState.Open Then
    app.Open()
    End If
    Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM ADMIN " & _
    " WHERE ID=" & intID, app)


    Dim dt As New DataTable
    da.Fill(dt)
    Me.Textbox1.Text = CStr(intID)
    Me.txtname.Text = CStr(dt.Rows(0).Item("Name"))
    Me.Textbox1.Tag = intID
    Me.add.Text = "Update"
    Me.btnEdit.Enabled = True
    End If
    app.Close()
    End If()

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    I have never used ExecuteNonQuery.

    Regardless, don't use Text property. Why use Tag property? Why even update ID field?

    Also need a space after apostrophe before WHERE clause so text won't run together.

    cmd.CommandText = "UPDATE ADMIN SET Name='" & Me.txtname & "' WHERE ID=" & CStr(Me.Textbox1)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    christing is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    10
    Thanks for your reply my message after i try the code you give for me....i am still get error on Syntax error in UPDATE statement.
    cmd.CommandText = "UPDATE ADMIN" & _
    "SET" & _
    "Name = " & Me.txtname.Text & _
    "WHERE ID=" & CStr(Textbox1.Text)

    cmd.CommandText = "UPDATE ADMIN " & _
    " SET" & _
    " [Name]='" & Me.txtname.Text & "'" & _
    " WHERE [ID]=" & CStr(Textbox1.Tag)
    I SUCCESS ALREADY

  6. #6
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    As June has said stop using the .Text property , and add a space after / before the where clause.
    In fact do it properly and build your sql statement as a string so you can debug it ;

    Code:
    Dim sSql As string
    
    sSql = "UPDATE ADMIN SET [Name]='" & Me.txtname & "' WHERE ID=" & CStr(Me.Textbox1)
    
    Debug.Print sSql
    CurrentDb.Execute sSql , DbSeeChanges
    If your ID field is a number then why are changing it to a string ?
    Also Name is a reserved word so will need putting in square brackets, or preferably change the field name.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 08-01-2019, 03:29 PM
  2. Replies: 5
    Last Post: 09-29-2015, 12:07 PM
  3. Replies: 6
    Last Post: 10-30-2013, 05:17 PM
  4. Replies: 3
    Last Post: 07-23-2011, 08:34 AM
  5. Replies: 0
    Last Post: 02-15-2007, 03:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums