抱歉,我是Vb的初学者,因此我正在寻找一种简单的方法来使用来自访问数据库的数据填充combox。
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;
如何将上述代码转换为vb
答案 0 :(得分:1)
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
有组合框名称。不要忘记在代码的最顶层导入OleDb,如下所示:
imports System.Data.OleDb