1 我先在设计时将datagrid绑定到adodc控件
然后在一个点击按钮的过程中写了这样的代码
Adodc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb;Persist Security Info=False"
Adodc.CommandType = adCmdText
Adodc.RecordSource = "select * from db1"
...
但是为什么datagrid控件中显示不出数据呢?
2 我在ADODC的属性设置COMMANDTEXT时老是说语法错,不知道正确的语法是什么?
然后在一个点击按钮的过程中写了这样的代码
Adodc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb;Persist Security Info=False"
Adodc.CommandType = adCmdText
Adodc.RecordSource = "select * from db1"
...
但是为什么datagrid控件中显示不出数据呢?
2 我在ADODC的属性设置COMMANDTEXT时老是说语法错,不知道正确的语法是什么?
Dim cn As New ADODB.Connection
Dim rs As New Recordset
cn.ConnectionString = "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=pubs;User Id=sa;Password=lyjlee;"
cn.Open
rs.Open "authors", cn, adOpenKeyset, adLockOptimisticset Adodc.datasource=rs
Adodc.Refreshrs.close
cn.close
“窗体布局”选择 网格(数据表)
“绑定类型”选择 ADO数据控件
data1.recordsource="select........"
data1.refersh
即可
你的DATAGRID控件和ADODC控件连接了吗?2.
你的语句是怎么写的!?
2 select * from 表名
在 Adodc.RecordSource = "select * from db1" 之后加2 正确的语法就是sql语法不过表名最好用[]括起
Set Rst = New ADODB.Recordset
If SQL.State > 0 Then
SQL.Close
End If
SQL.Open "Provider=SQLOLEDB.1;Persist Security Info=True;Initial catalog=GPSINFO;Data Source=" & DataServName & ";User ID=" & DBUser & ";Password=" & DBPass & ";"
数据库名 机器名 =zhy sa
SQL.CommandTimeout = 0
' SQL.Execute "insert into .../select * from db1"
DBFlg = True
SQL.Close
<datasource> is the name odbc data source as defined on the local system in the odbc configuration utility. CAUTION! the account under which the server is run must be granted permission to access the data source.
<user name> is the name which to log into the data source.
<password> is the password with which to access the data source.
1) 凡是你在工程部件中添加的工具,都要到 工程 引用中引用相信的驱动,
2) 然后你在 用上面的代码连接数据库,
3) 然后才开始对数据库操作,
上面的代码中加了判断是否连接成功的语句,(if 中的)
SQL.Execute" …………" 引号中书写 你的 SQL 语句的命令象现在你用的是Adodc.RecordSource"SQL 语句……"