K
kjvt
Jay,
This code works!
And, it helps isolate what is going wrong with my code, but I don't
understand why my code fails. Try the following modification to your
code:
Private Sub SqlServerDataBase()
Const PubsDataBase As String = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Data Source=.;Use Procedure
for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation
ID=MyWorkstation;Use Encryption for Data=False;Tag with column
collation when possible=False;Initial Catalog=pubs;"
Dim conn2 As New ADODB.Connection
Dim strProvider As String = PubsDataBase
conn2.Open(strProvider)
Dim rs As New ADODB.Recordset
rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
rs.Open("select * from titles", conn2)
Me.DataGrid1.DataSource = GetViewFromRS(rs)
Me.DataGrid2.DataSource = GetViewFromRS(rs)
End Sub
Private Function GetViewFromRS(ByVal pRS As ADODB.Recordset) As
DataView
Dim sAdapter As OleDb.OleDbDataAdapter = New
OleDb.OleDbDataAdapter
Dim sTable As System.Data.DataTable = New DataTable
sAdapter.Fill(sTable, pRS)
GetViewFromRS = New DataView(sTable)
End Function
When I run this, the second datagrid has no rows. Do you have any
idea what makes this different from your example?
Many thanks to you and Cor for helping me through this.
Kees
This code works!
And, it helps isolate what is going wrong with my code, but I don't
understand why my code fails. Try the following modification to your
code:
Private Sub SqlServerDataBase()
Const PubsDataBase As String = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Data Source=.;Use Procedure
for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation
ID=MyWorkstation;Use Encryption for Data=False;Tag with column
collation when possible=False;Initial Catalog=pubs;"
Dim conn2 As New ADODB.Connection
Dim strProvider As String = PubsDataBase
conn2.Open(strProvider)
Dim rs As New ADODB.Recordset
rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
rs.Open("select * from titles", conn2)
Me.DataGrid1.DataSource = GetViewFromRS(rs)
Me.DataGrid2.DataSource = GetViewFromRS(rs)
End Sub
Private Function GetViewFromRS(ByVal pRS As ADODB.Recordset) As
DataView
Dim sAdapter As OleDb.OleDbDataAdapter = New
OleDb.OleDbDataAdapter
Dim sTable As System.Data.DataTable = New DataTable
sAdapter.Fill(sTable, pRS)
GetViewFromRS = New DataView(sTable)
End Function
When I run this, the second datagrid has no rows. Do you have any
idea what makes this different from your example?
Many thanks to you and Cor for helping me through this.
Kees