
首先连接数据库,读取数据 绑定控件 textbox1.text=数据库取出值
方法二、写代码
//sql语句string sql = string.Format("SELECT text FROM Test WHERE ID = {0})", 1)
//数据库名为Temp.mdb,表为Test,包含2个字段:ID 和 text
string DbConnectionString = "Data Source=Computer-PCUser ID=saPassword=123456Initial Catalog=TempPooling=true"
SqlConnection con = new SqlConnection(DbConnectionString)
SqlCommand cmd = new SqlCommand(sql, con)
cmd.CommandType = CommandType.Text
SqlDataReader myReader
con.Open()
myReader = cmd.ExecuteReader()
textBox1.Text = myReader["text"].ToString()
MessageBox.Show("完成!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
cmd.Cancel()
myReader.Close()
Private Sub Form_Load()Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0Data Source= " &App.Path &"\main12.mdbPersist Security Info=FalseJet OLEDB:Database Password=*********"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from save_type " '要显示的数据源
Adodc1.Refresh
Adodc1.Recordset.MoveFirst '移动到第一条记录
Combo1.Clear
For i = 0 To Adodc1.Recordset.RecordCount - 1 '循环添加吧
Combo1.AddItem Adodc1.Recordset.Fields(0).Value
Adodc1.Recordset.MoveNext '移动到下一条记录
Next i
End sub
首先你要有一个datatabel是你从数据库中查出来的,这个没问题吧绑定数据
comboBox1.DisPlayMember="要用于显示的字段名"
comboBox1.ValueMember="要用于作为值的字段名"
comboBox1.dataSource = datatable
这是一种方式。
纯手写,你复制过去,就能用了,但是大小写可能会错
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)