SyntaxError SyntaxError - 1 year ago 74
Vb.net Question

how to fill Combobox in vb 2010 with data from database (access database)

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>";
echo "<select name='project">";
echo "<option name='$fetch[projectname]'>$fetch[projectname]</option>";
echo "</select>";
echo "</form>";
endwhile;


how can i transform the above code to vbvb form with combobox

MAC MAC
Answer Source
        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