Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
VB
Imports System.Data.OleDb
Public Class ee
    Dim cnxnString As String = ("Provider=Microsoft.JET.OLEDB.4.0;" & _
"Data Source=D:\Mohamed Ayman\Donic.mdb")
    Dim cnxn As New OleDbConnection(cnxnString)
    Dim sql As New OleDbCommand
    Dim DataAdapter As New OleDbDataAdapter("SELECT * FROM [Clients]", cnxn)
    Dim cmdBuilder As New OleDbCommandBuilder(DataAdapter)
    Dim Clients As New DataTable

    Dim f As Integer = 0
    Dim r As String
    Private Sub bs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bs.Click
        Dim msg = "Do you want to save the changes?"
        Dim title = "Caution"
        Dim style = MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton2 Or _
        MsgBoxStyle.Critical
        Dim response = MsgBox(msg, style, title)
        If response = MsgBoxResult.Yes Then
            Dim sqlsearch As String
            sqlsearch = "Update * FROM Clients WHERE [Club] LIKE '" & ComboBox2.Text & "'" & " [FirstName] LIKE '" & tsearch.Text & "'" & " [SurName] LIKE '" & combobox.Text & "'" & "  "
            Dim adapter As New OleDb.OleDbDataAdapter(sqlsearch, cnxn)
            Dim dt As New DataTable("Clients")
            adapter.Fill(dt)      //Syntax error update statment
            f = 1
        End If
    End Sub
Posted
Updated 16-Oct-14 14:27pm
v3
Comments
[no name] 16-Oct-14 21:06pm    
http://www.w3schools.com/sql/sql_update.asp then once you have fixed your SQL, do some research on SQL injection and why you should use parameterized queries.

Change your UPDATE command: the syntax isn't even close!
SQL
UPDATE Clients SET MyColumn=MyValue, MyOtherColumn=MyOtherValue WHERE Club LIKE '%xxx%'
Is the general syntax you are looking for, but please, don;t do it like that! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
And then look at the rest of your code: since you almost certainly copy-n-pasted that from elsewhere, the rest of your application is wide open to anyone who "wants a laugh" to destroy your DB just by typing in your text boxes...
 
Share this answer
 
Comments
Maciej Los 17-Oct-14 2:15am    
Paul, it's MS Access database up to 2003 version.
Jet database does not accept %. Use * instead.
Few things:
1) UPDATE statement is wrong! Please read solution 1 with my comment.
2) To run query which modifies data, you need to call ExecuteNonQuery()[^] method.
3) Use parametrized queries instead.
SQL
PARAMETERS [firstName] CHAR, [club] CHAR;
UPDATE TableName SET Club=[club] WHER FirstName = [firstName]

To call this statement use AddWithValue method[^].
Please, see:
OleDbCommand.Parameters Property [^]
Configuring Parameters and Parameter Data Types[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900