从数据库中读取数据添加到combobox的Items选项中,运行程序时不管选择其中哪项,combobox.text都是空串
//读取添加到Items里面stringsql="selectSubjectNamefromSubject";SqlCommandcmd=newSqlCommand(sq...
//读取添加到Items里面
string sql = "select SubjectName from Subject";
SqlCommand cmd = new SqlCommand(sql, DBHelper.conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
cbo_selectQusetion.Items.Add((string)reader["SubjectName"]);
}
cbo_selectQusetion.text =="";//不管选择哪项都是空串,手动输入也一样。 展开
string sql = "select SubjectName from Subject";
SqlCommand cmd = new SqlCommand(sql, DBHelper.conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
cbo_selectQusetion.Items.Add((string)reader["SubjectName"]);
}
cbo_selectQusetion.text =="";//不管选择哪项都是空串,手动输入也一样。 展开
展开全部
数据库db1.mdb
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDbConnection _
("provider=microsoft.jet.oledb.4.0;data source=db1.mdb")
Dim mydataset As New DataSet()
Dim myadapter As New OleDbDataAdapter("select * from 考场表", conn)
conn.Close()
myadapter.Fill(mydataset, "考场表")
ComboBox1.DataSource = mydataset
ComboBox1.DisplayMember = "考场表.考场号 "
conn.Close()
End Sub
End Class
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDbConnection _
("provider=microsoft.jet.oledb.4.0;data source=db1.mdb")
Dim mydataset As New DataSet()
Dim myadapter As New OleDbDataAdapter("select * from 考场表", conn)
conn.Close()
myadapter.Fill(mydataset, "考场表")
ComboBox1.DataSource = mydataset
ComboBox1.DisplayMember = "考场表.考场号 "
conn.Close()
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询