I'm doing a project in vb.net back-end is MSACCESS...

I don't know how to store data from COMBO BOX and to RETRIVE data from database to COMBO BOX...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
        cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Ariff\Inventory\Inventory.mdb;Persist Security Info=False")
        cn.Open()
        str = "insert into Sales values(" & TxtCde.Text & "," & TxtDate.Text & ",'" & CmbCtgry.SelectedItem & "'," & TxtDscnt.Text & "," & TxtQty.Text & "," & TxtDesc.Text & " )"
        'string stores the command and CInt is used to convert number to string
        cmd = New OleDbCommand(str, cn)
        icount = cmd.ExecuteNonQuery
        MessageBox.Show(icount)
        'displays number of records inserted

    Catch ex As Exception
        MessageBox.Show(ex.Message & " - " & ex.Source)
        'MsgBox("Connection Error")
        cn.Close()
    End Try

End Sub

The error is: Syntax error (missing operator) in query expression

Plz help me to solve this prob... i have to finish my project very soon...

Thanks in advance...

Recommended Answers

All 5 Replies

try this

Private Sub FillCombo()
        Try
            Dim fillcon As New OleDbConnection(conString)
            Dim asql As String = ("SELECT ItemName FROM ItemMaster ORDER BY ItemName")
            Dim da As New OleDbDataAdapter(asql, fillcon)
            Dim ds As New DataSet
            da.Fill(ds)

            ItemNameCombo.ValueMember = "ItemName"
            ItemNameCombo.DataSource = ds.Tables(0)
            ItemNameCombo.SelectedIndex = 0

        Catch ex As Exception
            MsgBox("ERROR : " & ex.Message.ToString)
        End Try
    End Sub

just call that function..it set the value of combo box to a database

S... It worked...

Thanks very much...

But i also need how to store the details from combo box to database...

How to make this thread as SOLVED one...?

So that i have to make this as solved...

Thanks in advance

hello frnd i am new in vb please help me in vb basic program, vb to database connection made as well as all of them please.............

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.