|
-
Aug 29th, 2005, 05:26 PM
#1
Thread Starter
Lively Member
[RESOLVED] ADODB Recordset
Hello,
I'm here again for some help.
Here is what i have,
VB Code:
Dim ConnectionString As String = "Provider=MSDASQL.1;Password=101098;Data Source=main;Persist Security Info=True"
'Create my objects
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Try
conn.Open(ConnectionString)
cmd.ActiveConnection = conn
cmd.CommandText = "SELECT customername FROM customers"
'make a recordset here
Catch ex As Exception
Debug.WriteLine(ex.Message.ToString)
End Try
I need help build a recordset from that query and displaying it in a datagrid or a flexgrid.
Thanks in advance!
-
Aug 29th, 2005, 05:38 PM
#2
Re: ADODB Recordset
Why not use ADO.NET and a DataGrid?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 29th, 2005, 05:49 PM
#3
Thread Starter
Lively Member
Re: ADODB Recordset
could you please provide an example?
-
Aug 29th, 2005, 06:06 PM
#4
Re: ADODB Recordset
You need to import the SQL client namespace. Then set up a connection to your db.
VB Code:
Imports System.Data.SqlClient
Public Function DBConn() As SqlConnection
'<CONNECT TO SQL DB>
Dim oSQLCnn As SqlConnection
Try
oSQLCnn = New SqlConnection
oSQLCnn.ConnectionString = "Data Source=MyServer;Initial Catalog=MyDB;Integrated Security=SSPI;" 'Integrated Security
oSQLCnn.Open()
DBConn = oSQLCnn
Catch exSQL As SqlException
MessageBox.Show(exSQL.Errors.Item(0).Message, exSQL.Errors.Item(0).Number.ToString & ": " & _
exSQL.Errors.Item(0).Source, MessageBoxButtons.OK, MessageBoxIcon.Error)
DBConn = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error)
DBConn = Nothing
End Try
'</CONNECT TO SQL DB>
End Function
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 29th, 2005, 06:07 PM
#5
Re: ADODB Recordset
All the data access examples in the 101 samples are ADO.NET except the one that explicitly says it uses ADO 2.6. Get the 101 samples from the sticky thread at the top of this very forum.
-
Aug 29th, 2005, 06:10 PM
#6
Re: ADODB Recordset
Then we need to make the connection and populate a datatable.
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oSQLCnn As SqlConnection
oSQLCnn = DBConn()
Dim dt As New DataTable
Dim da As New SqlDataAdapter("SELECT * FROM Table1", oSQLCnn)
da.Fill(dt)
Me.DataGrid1.DataSource = dt
Me.DataGrid1.ReadOnly = True' Or False
Me.DataGrid1.ColumnHeadersVisible = True
Me.DataGrid1.CaptionVisible = False
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 29th, 2005, 06:27 PM
#7
Thread Starter
Lively Member
Re: ADODB Recordset
thanks for ur reply.
But i have an access database i dont run a sql server. Any way to modify that to work with access?
-
Aug 29th, 2005, 06:32 PM
#8
Re: ADODB Recordset
Doh! I should have asked first but its not too much different. There is a OLEDBDataAdapter, OLEDBConnection, and OLEDBCommand. Dont have time right now to write an example, leaving for home, but if you cant get it or no one else posts one, then I will.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 29th, 2005, 07:02 PM
#9
Thread Starter
Lively Member
Re: ADODB Recordset
looking forward to it 
i've spent about 6 hours today trying to do 3 things... and still not much luck
-display query results in a datagrid or a flexgrid
-pull field values from a recordset
-update database
-
Aug 29th, 2005, 07:12 PM
#10
Re: ADODB Recordset
Wherever Rob has used "Sql", you would use "OleDb". You would also need to import the System.Data.OleDb namespace, where for Rob's code you would import SqlClient. You'll have to change the connection string for OleDb as well. Try www.connectionstrings.com
-
Aug 30th, 2005, 05:41 AM
#11
Thread Starter
Lively Member
Re: ADODB Recordset
VB Code:
Dim ConnString As String = "Provider=MSDASQL.1;Password=101098;Data Source=main;Persist Security Info=True"
Dim Query As String = "SELECT customer FROM customers "
'Create a connection object to connect to the database
Dim conn As New OleDbConnection(ConnString)
'Create a command object to run queries against the database
Dim cmd As New OleDbCommand(Query, conn)
'open the connection to the database
conn.Open()
'so now how do i execute the whole thing and bind the data to a datagrid
'close the connection
conn.Close()
is this anywhere close? no how would i get a recordset from there and have it be displayed in a datagrid?
-
Aug 30th, 2005, 05:52 AM
#12
Re: ADODB Recordset
Rob's code is:
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oSQLCnn As SqlConnection
oSQLCnn = DBConn()
Dim dt As New DataTable
Dim da As New SqlDataAdapter("SELECT * FROM Table1", oSQLCnn)
da.Fill(dt)
Me.DataGrid1.DataSource = dt
Me.DataGrid1.ReadOnly = True' Or False
Me.DataGrid1.ColumnHeadersVisible = True
Me.DataGrid1.CaptionVisible = False
End Sub
Your code should be to the effect of:
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New OleDb.OleDbConnection("connection string here")
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Table1", con)
da.Fill(dt) 'Retrieve data into DataTable.
Me.DataGrid1.DataSource = dt 'Bind DataGrid to DataTable.
Me.DataGrid1.ReadOnly = True' Or False
Me.DataGrid1.ColumnHeadersVisible = True
Me.DataGrid1.CaptionVisible = False
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|