vb连接access 数据库并将结果输出到文本框。在线等高手
想把数据库里的东西显示到文本框里。添加了一个按钮当点击按钮之后将数据分别显示到对应的文本框。在线等,
[解决办法]
要用SQL语句,返回数据后在放到TextBox里,三两句说不清楚,帮你顶一下
//----------------------------------------- //----------------------------------------- public static DataTable OleDbExecuteReader(string connStr, string OleDbStatements, params OleDbParameter[] OleDbParameters) { using (DataTable dt = new DataTable()) { using (OleDbConnection conn = new OleDbConnection(connStr)) { if (conn.State != ConnectionState.Open) conn.Open(); using (OleDbCommand cmd = new OleDbCommand(OleDbStatements, conn)) { cmd.Parameters.Clear(); foreach (OleDbParameter SqlParameter in OleDbParameters) { cmd.Parameters.Add(SqlParameter); } using (OleDbDataAdapter da = new OleDbDataAdapter(cmd)) { da.Fill(dt); } return dt; } } } }
[解决办法]
Dim connectionstring As String connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\pigsystem\pigsystem\zmsf.mdb" Dim querystring As String = "Select * from 数据库中的表 where 表中的字段='" &字段显示的条件& "'" '这个意思按某个字段的某种条件确定你要显示的数据库行的位置 Dim conn As New OleDb.OleDbConnection(connectionstring) Try conn.Open() Dim cmd As New OleDb.OleDbCommand(querystring, conn) Dim reader As OleDb.OleDbDataReader reader = cmd.ExecuteReader() reader.Read() textbox1.text = reader("表中的字段1") textbox2.text = reader("表中的字段2") ........ Catch ex As Exception End Try
[解决办法]