Title: how to fill Combobox in vb 2010 with data from database (access database)
Tags: vb.net;visual-studio-2010
Question: Sorry am a beginer to Vb, therefore am looking for a simple way to fill combox with data from access database.
PHP WAY
#connection first.
$sql = "select * from projects";
$select_records = mysqli_query($con,$sql);
while($fetch = mysqli_fetch_array($select_records)):
echo "<form&gt;";
echo "<select name='project"&gt;";
echo "<option name='$fetch[projectname]'&gt;$fetch[projectname]</option&gt;";
echo "</select&gt;";
echo "</form&gt;";
endwhile;
how can i transform the above code to vb
Comment: what database are you using?

Comment: do you know how to query in vb? did you already connect ms access to your vb code?

Comment: for vb is `access database`, i want the code in vb using access database

Here is the accepted answer: Dim query as String
Dim con as OleDbConnection
Dim command as OleDbCommand
Dim reader as OleDbDataReader
con.Open()
query = "select * from projects"
command = New OleDbCommand(query, con)
reader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
cb.Items.Add(reader("FieldName"))
End While
End If
cb there is the combobox name. Don't forget to import OleDb at the topmost of your code like this:
imports System.Data.OleDb
Comment for this answer: that was OleDbDataReader, sorry. I did that code without compiler so I got  it wrong.. it's good that you got it now. :) @SyntaxError
Comment for this answer: mac am having an error on Dim reader as OleDbReader; Error: OleDbReader is not defined


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:05/27/15', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<vb.net><visual-studio-2010>', 'Title': 'how to fill Combobox in vb 2010 with data from database (access database)', 'ViewCount': 10378, 'id': 30478516, 'user_AboutMe': '', 'user_AccountId': 5909106.0, 'user_DisplayName': 'SyntaxError', 'user_Reputation': 27.0, 'user_Views': 52.0, 'user_id': 4649925.0}}