Working with access in .NET

BigSi

Member
Joined
Feb 6, 2003
Messages
22
hi,
I have been searching around for working with access in .Net for a while now as I am producing my first .net application since I am used to nworking in vb6.
Im hoping to try and get data from certain fields in access to be displayed in a text box.
This is probably an easy task, but I have seen posts about this on the forum refering to using the .net method instead of the .com.
So far I have successfully filled a listbox with database contents, and now I am wondering how I should be connecting to my access database correctly as I can now refer to my allready established oledb adapter. - should i br refrencing this in a connection string?

Anyway, Im hoping someone can provide me with some code, or a shove in the right direction on creating a database connection, and then filling a text box with a value for when a button is pushed,

Many thanks
Si
 
This is what I have so far ....

-----------------------------------
Private Sub lstAccounts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstAccounts.SelectedIndexChanged
Displays the primary key id of the firm selected in the list box
txtCompanyName.Text = lstAccounts.SelectedValue
Dim conn As New OleDb.OleDbConnection()
Dim MyRs As ADODB.Recordset
conn.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\simonlane\My Documents\Visual Studio Projects\CompanyLearningAccount\Database\CompanyLearningAccount.mdb;")
conn.Open()

MyRs = New ADODB.Recordset()
query refers to the primary key field, which is found in the list box
****For some reason the line of code below is failing to work!
MyRs.Open("SELECT * FROM Firm where FirmId = & lstAccounts.SelectedValue & ", conn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)

some code to access records field values, and declaire them such as fieldFirmName = recordsetfieldvaluex
MyRs.Close()
conn.Close()
txtFirmAddress1.text = ExtractedDBValue
End Sub
---------------------------------------------------------------------------


I cant seem to open my recordset, and also I am unsure how to then extract the recordsets field values and store them as a variable
 
Excellent - thanks for the refrence, it looks quite helpfull so ill give it a go!
Code:
 just testing the vb code
Cheers
 
Back
Top