Hi there,
I am trying to connect my ClassLibrary to a SQL database.
I've already added a new datasource (named PatientsDS_new) to my database, I've let VB copy it to local project etc. .
The database contains a table (names patients), which is imported too.
This is also the table I want to perform actions on.
Now the problem is that in 'form applications', i can select a row like this:
Dim row As patientsDSx.patients_1Row = Me.PatientsDSx.patients_1.FindByPatientID(id)
But in my 'ClassLibrary' I can only get to this:
Dim row As patientsDS_new.patients_1Row
I want to be able to do the same as in my form-code, but I don't know how to achieve this.
This is the code I am using:
Public Sub SaveToDB(ByVal opt As String, ByVal id As Integer, ByVal lastname As String, ByVal firstname As String, ByVal address As String, _
ByVal city As String, ByVal zip As String, ByVal telnr As String, ByVal gsmnr As String, _
ByVal notes As String, ByVal lastvisit As String, ByVal bloodgroup As String, ByVal doctor As String, _
ByVal hif As String, ByVal regnr As String, ByVal bd As Date, ByVal age As String, _
ByVal visits As String, ByVal debts As String)
opt = opt.ToLower
Select Case opt
Case "add"
Dim age_ As Integer = DateDiff(DateInterval.Year, bd, Now)
Dim row As patientsDS_new.patients_1Row ' This has to change
row.BeginEdit()
row.LastName = lastname
row.FirstName = firstname
row.Address = address
row.City = city
row.ZIP = zip
row.TelNr = telnr
row.GSMNr = gsmnr
row.Notes = notes
row.LastVisit = lastvisit
row.BloodGroup = bloodgroup
row.Doctor = doctor
row.HIF = hif
row.RegNr = regnr
row.BirthDate = bd
row.Age = age_
row.Visits = visits
row.Debts = debts
row.AcceptChanges()
row.EndEdit()
End Select
End Sub
Any help would be welcome.
Grtz, Tom.

Connecting to SQL database from within Class Library
cmumford
as you dont have a form - the designer wizard will not generate the underlying code for you in the class library.
You will need to code up the population of the dataset within the class library using ADO.NET or pass the dataset from a form to the class library.
some useful links
ADO.net Quick start >>> http://www.asp.net/QuickStart/howto/doc/adoplus/overviewcontents.aspx
Connecting and Retrieving Data in ADO.NET >>> http://msdn2.microsoft.com/en-us/library/ms254937.aspx
sqlconnection >>> http://msdn.microsoft.com/vbasic/reference/data/default.aspx pull=/library/en-us/dnsql90/html/mandataaccess.asp#mandataac_topic5
featching data into your app >> http://msdn2.microsoft.com/en-us/library/ms171918(VS.80).aspx
many database connection strings >>> http://www.connectionstrings.com/
Once you have the dataset populated in the class library its identical to work with as it was when it was generated on the form.