Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to connect to database with ADODB

Status
Not open for further replies.

niceguyismad

Programmer
Apr 13, 2007
1
US
Hello everyone, I know how to connect to database with ADODB with classes. I need to know how to connect to it without class. little about this code. I have a form with information about patient history and patient will have many history form. I want to put a next and previous button on it. u can brown the patient history however it a error coming up Errior is "object reference not set to instance ofanobject" for that line of code If (rowIndex < rst.RecordCount - 1) Then
I am not so is it the code or connecting to database is wrong. Can someone take look and tell me what i am doing wrong please.



Dim msgString As String = "msg"
Dim sqlString As String = "SELECT * FROM(PatientHistory) WHERE (((patienthistory.patientid)= txtpatientid.Text ));"

Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ConnectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FHISData.mdb"
Dim Emp As New CPhistory
cnn = New ADODB.Connection
cnn.Open(ConnectString)

Dim dbHandler = New CDataDBHandler
rst = dbHandler.ExecuteSQL(sqlString, msgString)
Try
rst.MoveFirst()
Catch ex As System.NullReferenceException
rst = Nothing
End Try

If (rowIndex < rst.RecordCount - 1) Then
rowIndex += 1
Displayhistory(Emp)
End If
 
I believe the problem is in your SQL string. You have:

Dim sqlString As String = "SELECT * FROM(PatientHistory) WHERE (((patienthistory.patientid)= txtpatientid.Text ));"

Whic will put the actual text "txtpatientid.Text" in the SQL, NOT the value that is in txtpatientid. Try this (changes in red):

Dim sqlString As String = "SELECT * FROM(PatientHistory) WHERE (((patienthistory.patientid)=[red]" & txtpatientid.Text & "[/red]));"



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
jebenson,

I missed that one, I was looking at the number of brackets to make sure thay balanced, totally missed the textbox in the string... :)

Nice find or i'm just blind...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top