数据源设置不对吧请参阅
Public Rs_Jc_Shhy_Csb As New ADODB.Recordset
With Rs_Jc_Shhy_Csb
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = adoCN
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = "SELECT * FROM Jc_Shhy_Csb WHERE hth='" & W_Jc_Shhy.Text1(0).Text & "'"
.Open
End WithSet DataGrid1.DataSource = Rs_Jc_Shhy_Csb
Public Rs_Jc_Shhy_Csb As New ADODB.Recordset
With Rs_Jc_Shhy_Csb
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = adoCN
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = "SELECT * FROM Jc_Shhy_Csb WHERE hth='" & W_Jc_Shhy.Text1(0).Text & "'"
.Open
End WithSet DataGrid1.DataSource = Rs_Jc_Shhy_Csb
recordset 而不是 forward-only 和 dynamic ADO recordset。更详细的信息,您可以参考以下文章:ID: Q278408 PRB: DataGrid Cannot Be Bound to a Non-Bookable Recordset
<http://support.microsoft.com/default.aspx?scid=kb;EN-US;q278408>您可以参考以下的示例代码来解决您的问题:Dim cnn as New ADODB.Connection
Dim cmd as New ADODB.Command
Dim rs as New ADODB.Recordsetcnn.Open "Provider=SQLOLEDB;Data Source=myServer;Initial Catalog=testdb;User Id=sa;Password="
cmd.ActiveConnection = cnn
cmd.CommandText = "Exec SPTest"
rs.CursorType = adOpenStatic
rs.Open cmd
Set DataGrid1.DataSource = rs - 微软全球技术中心 VB技术支持 立即参加微软认证的“最有价值专家”评选,赢取价值万元以上的丰富奖品!详情参见(http://www.csdn.net/expert/Topic/456/456919.shtm) 本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。