Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

VS 2010 Need help on saving database

$
0
0
Hello,

I need some helps on my coding. I'm using a button to allow user to make changes to the quantity and price, which will in turn be saved into my SQL database(Table Name is Product). However, when I click the save, it shows errors on Syntax error (missing operator) in query expression. My coding is as follow:
Code:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim con As New OleDb.OleDbConnection
        Dim dbProvider As String
        Dim dbSource As String
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String
        Dim product As String

        dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
        dbSource = "Data Source = C:\Ah zhu\Project\Project\Project.accdb;Persist Security Info=False;"

        con.ConnectionString = dbProvider & dbSource

        con.Open()

        product = Product_TitleTextBox.Text
        sql = "SELECT * FROM [Product] WHERE Product Title = '" & product & "'"
        da = New OleDb.OleDbDataAdapter(sql, con)

        da.Fill(ds, "Product")  ' it show error - Syntax error (missing operator) in query expression 'Product Title = 'Source Naturals, Skin Ethernal Cream''.

        Dim cb As New OleDb.OleDbCommandBuilder(da)

        ds.Tables("Product").Rows(0).Item("Product Price") = Product_PriceTextBox.Text
        ds.Tables("Product").Rows(0).Item("Quantity") = QuantityTextBox.Text

        da.Update(ds, "Product")

        MsgBox("Data Updated!")

        MsgBox("Database is now open")

        con.Close()

        MsgBox("Database is now Closed")

    End Sub

Could anyone help to solve it? Thank you in advanced...

Viewing all articles
Browse latest Browse all 27348

Trending Articles