954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Retriving Data from Database to COMBO BOX

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...

Noorul Ariff
Light Poster
39 posts since Oct 2010
Reputation Points: 9
Solved Threads: 1
 

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

marniel647
Newbie Poster
6 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

S... It worked...

Thanks very much...

Noorul Ariff
Light Poster
39 posts since Oct 2010
Reputation Points: 9
Solved Threads: 1
 

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

Noorul Ariff
Light Poster
39 posts since Oct 2010
Reputation Points: 9
Solved Threads: 1
 

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

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

Thanks in advance

Noorul Ariff
Light Poster
39 posts since Oct 2010
Reputation Points: 9
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: