When I first use .NET I get Started to Connect to my Databases and when I do, I finally found out that I need a Correction. So I hope to have a better answer in here. Thanks.
I use to Connect to my Database is
Dim Connect as Adodb.Connection
Set Connect = "Provider blah blah blah
I just need a question here...
When I query, I use this
dim rs as adodb.recordset
set rs = Connect.Execute("SELECT blah FROM Blah")
can I really use this in .NET? or it will only be available in Visual Basic? thanks in Advance..
26-08-2005 at 06:36 AM
TJ_01 Level: Wizard
Registered: 24-08-2005 Posts: 317
There are some parameters or syntax used in .NET that are not applicable in VB6 and vice versa. I used this sample code in connecting database using .NET.
' Create a connection string
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\Northwind.mdb"
Dim sql As String = "SELECT CustomerId, CompanyName, ContactName From Customers"
29-08-2005 at 03:31 AM
~Bean~ Level: VB Guru
Registered: 07-04-2003 Posts: 480
.NET does not have a recordset object, at first I was like WTF but now that I have been working with .NET for a few months I don't miss it a bit. You can use old ASP code in a .NET project. but I recommend getting up to speed with how .NET ADO has changed (into ADO.NET......go figure...)
'Sample Data Access Using SQL Server
'(for other DB use OleDB)
'Before your class make sure you have...
Imports System.Data.SQLClient 'for SQL Server conn
'In your procedure/function...
Dim objConn As SqlConnection
'your connection string will be pretty much the same as before...
objConn = New SqlConnection(connection_string)
Dim oCmd as New SqlCommand("SELECT id FROM tblTable", objConn)
oCmd.CommandType = CommandType.Text
Dim oReader as SqlDataReader
oReader = oCmd.ExecuteReader
'do something with data
myIDs = oReader.Item("id")
This example shows looping thru a data reader. Although slower than the data reader, you should also check out the Dataset object in Help or look for some examples on that because it is just so dang useful....(binding to a datagrid)
Eggheads unite! You have nothing to lose but your yolks.
03-09-2005 at 01:36 AM
Bharathi Level: Scholar
Registered: 11-04-2005 Posts: 31
[Edited by Bharathi on 17-05-2013 at 12:46 PM GMT]