如何把通过条件语句查询后的数据库里的一列内容赋值给Combobox 50
3个回答
展开全部
给你完整代码参考
Private Sub Command2_Click()
Dim CnnStr As String
CnnStr = "provider=Microsoft.jet.OLEDB.4.0;Persist security info= False; Data source=" & App.Path & "\数据库名称.mdb"
adodc1.ConnectionString = CnnStr
adodc1.CommandType = adCmdText
adodc1.RecordSource = "select * from 表单 where 姓名='" & Text1.Text &"'"
adodc1.Refresh
'设置DataGrid显示查询结果
Set DataGrid1.DataSource =adodc1
DataGrid1.Refresh
Combo1.Clear
Do While Not adodc1.Recordset.EOF
Combo1.AddItem adodc1.Recordset.Fields("姓名").Value
adodc1.Recordset.MoveNext
Loop
End sub
Private Sub Command2_Click()
Dim CnnStr As String
CnnStr = "provider=Microsoft.jet.OLEDB.4.0;Persist security info= False; Data source=" & App.Path & "\数据库名称.mdb"
adodc1.ConnectionString = CnnStr
adodc1.CommandType = adCmdText
adodc1.RecordSource = "select * from 表单 where 姓名='" & Text1.Text &"'"
adodc1.Refresh
'设置DataGrid显示查询结果
Set DataGrid1.DataSource =adodc1
DataGrid1.Refresh
Combo1.Clear
Do While Not adodc1.Recordset.EOF
Combo1.AddItem adodc1.Recordset.Fields("姓名").Value
adodc1.Recordset.MoveNext
Loop
End sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.comboBox1.Items.Clear();//清空ComBox
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
OleDbConnection Connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "jk_st.mdb");
Connection.Open();//打开连接
OleDbCommand command = new OleDbCommand("select mc from goal_add where mc<>'总部'", Connection);
OleDbDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
this.comboBox1.Items.Add(dataReader[0].ToString());//循环读取数据
}//end block while
dataReader.Close();//关闭DataReader
Connection.Close();//关闭连接
comboBox1.SelectedIndex = 0; //默认选中第一条数据
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
OleDbConnection Connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "jk_st.mdb");
Connection.Open();//打开连接
OleDbCommand command = new OleDbCommand("select mc from goal_add where mc<>'总部'", Connection);
OleDbDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
this.comboBox1.Items.Add(dataReader[0].ToString());//循环读取数据
}//end block while
dataReader.Close();//关闭DataReader
Connection.Close();//关闭连接
comboBox1.SelectedIndex = 0; //默认选中第一条数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
查询:
select 字段 from 表 group by 字段
记录:
do while not rs.eof then
combbox.item.add(rs("字段"))
rs.movenext
loop
select 字段 from 表 group by 字段
记录:
do while not rs.eof then
combbox.item.add(rs("字段"))
rs.movenext
loop
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询