SQL与VB连接时怎样在vb窗口中显示出sql表中的内容?如数据库名为xscj,其中一个表为xs,在vb中做一个学生
发布网友
发布时间:2022-05-03 09:26
我来回答
共4个回答
热心网友
时间:2023-10-19 02:06
要用到ADO对象(含ADO.Connect、ADO.Recordset)和DataGrid控件,前者用于按条件读取数据库数据,后者用于绑定显示读出来的数据。
SQL语句可以这样写:
select * from xs where 学号='某学号'
热心网友
时间:2023-10-19 02:06
在查询Click中写:
With Adodc1
.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog= 数据库;Data Source=服务器 "
.CommandType = adCmdText
if 选号 then
.RecordSource = "SELECT * from xs wHERE sID='"& txtID.Text&"'"
else
.RecordSource = "SELECT * from xs wHERE sName='"& txtID.Text&"'"
end with
set datagrid1.datasource=adodc1
大概就这样子,自己优化
热心网友
时间:2023-10-19 02:06
要用到ADO对象(含ADO.Connect、ADO.Recordset)和DataGrid控件,前者用于按条件读取数据库数据,后者用于绑定显示读出来的数据。
SQL语句可以这样写:
select * from xs where 学号='某学号'
热心网友
时间:2023-10-19 02:06
Option Explicit
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim Const conn As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=xscj;Data Source=服务器名(你电脑的名字)"
Private Sub Command1_Click()
Dim sql As String
Dim rs_find As New ADODB.Recordset
If Option1.Value = True Then
sql = "select * from xs "
End If
If Option2.Value = True Then
sql = "select * from xs where 姓名='" & Text1.Text & "'"
End If
If Option3.Value = True Then
sql = "select * from xs where 学号='" & Text1.Text & "'"
End If
rs_find.CursorLocation = adUseClient
rs_find.Open sql, conn, adOpenKeyset, adLockPessimistic
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
Set DataGrid1.DataSource = rs_find
End Sub
热心网友
时间:2023-10-19 02:07
你是SQL不会写吗?那我把SQL写一下吧
select sum(数量) from 表 where 时间 between A and B(也可以时间<=A and 时间>=B)
不加where条件是第一个问题。加了是第二个问题
热心网友
时间:2023-10-19 02:06
在查询Click中写:
With Adodc1
.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog= 数据库;Data Source=服务器 "
.CommandType = adCmdText
if 选号 then
.RecordSource = "SELECT * from xs wHERE sID='"& txtID.Text&"'"
else
.RecordSource = "SELECT * from xs wHERE sName='"& txtID.Text&"'"
end with
set datagrid1.datasource=adodc1
大概就这样子,自己优化
热心网友
时间:2023-10-19 02:06
Option Explicit
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim Const conn As String = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=xscj;Data Source=服务器名(你电脑的名字)"
Private Sub Command1_Click()
Dim sql As String
Dim rs_find As New ADODB.Recordset
If Option1.Value = True Then
sql = "select * from xs "
End If
If Option2.Value = True Then
sql = "select * from xs where 姓名='" & Text1.Text & "'"
End If
If Option3.Value = True Then
sql = "select * from xs where 学号='" & Text1.Text & "'"
End If
rs_find.CursorLocation = adUseClient
rs_find.Open sql, conn, adOpenKeyset, adLockPessimistic
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
Set DataGrid1.DataSource = rs_find
End Sub
热心网友
时间:2023-10-19 02:07
你是SQL不会写吗?那我把SQL写一下吧
select sum(数量) from 表 where 时间 between A and B(也可以时间<=A and 时间>=B)
不加where条件是第一个问题。加了是第二个问题