Question Database Access

JimM

Member
Joined
Jun 21, 2011
Messages
6
Programming Experience
10+
I use to write queries in VB6 to retrieve data and manipulate like this:

Public Function GetInvoiceHdrID(lInvNo) As Long
Dim sSQL As String
Dim rst As ADODB.Recordset
Dim Conn As ADODB.Connection

On Error GoTo ErrorHandler
Set rst = New ADODB.Recordset
Set Conn = New ADODB.Connection
Conn.ConnectionString = gsConnStr
Conn.CursorLocation = adUseClient
Conn.ConnectionTimeout = 60
Conn.Open

sSQL = "Select InvHdrID from tblInvHdr where InvoiceNo = " & lInvNo
rst.Open sSQL, Conn, adOpenForwardOnly, adLockReadOnly
If rst.RecordCount > 0 Then
GetInvoiceHdrID = rst("InvHdrID")
Else
GetInvoiceHdrID = 0
End If
Set rst = Nothing
Conn.Close
Set Conn = Nothing

Exit Function

How can I do stuff like this with VB.net?
Thanks
 
In VB.NET you use ADO.NET for data access. There are ADO.NET tutorials all over the place. You might like to start with the Data Walkthroughs link in my signature. If you'd rather write more of the data access code by hand, check out these examples:

Retrieving and Saving Data in Databases
 
Viewing SQL

I am using the method you outlined in Saving changes directly to one or more records in the database. Is there a way to view the actual SQL?

All I see is the ...@Variable, not what is actually generated.

Thanks for your help
 
That's all you see because that's all there is. The parameters values are not substituted into the SQL code. The SQL code and parameter values are sent to the database separately.
 
Back
Top