|
-
Oct 10th, 2005, 05:46 AM
#1
Thread Starter
Frenzied Member
Error on connection open
Hi ,
Can someone please tell what does this error refers to. Im getting it on the Line 92 below. thanks
Object reference not set to an instance of an object.
Line 92: myCommand.Connection.Open()
Last edited by angelica; Oct 10th, 2005 at 06:14 AM.
-
Oct 10th, 2005, 06:25 AM
#2
Fanatic Member
Re: Error on connection open
I think you're missing a closing bracket on the end of your declaration
should read -
VB Code:
...dropdschool.SelectedValue.ToString & "')", MyConn[b])[/b]
Another thing... is your IDNumber a string or a numeric, if it's a numeric you don't need the single quotes round the value.
Cheers Al
-
Oct 10th, 2005, 06:27 AM
#3
Fanatic Member
Re: Error on connection open
Hmmm it seems you've moved the goal posts??
-
Oct 10th, 2005, 07:18 AM
#4
Thread Starter
Frenzied Member
Re: Error on connection open
hey,
thanks for your reply. As you said the error is in the string. well I dont know how to handle them right and I keep changing to see where I have my mistake.
Im posting my whole string just in case you can tell me where Im doing wrong:
VB Code:
Dim myCommand As New OleDbCommand("INSERT INTO ApplicantsDetails(IDNumber,Course1,Course2,FirstName, LastName,Mobile,HomeTel,Email,School) VALUES('" & ID_No.Text & "' ,'" & _
dropdcourse1.SelectedValue.ToString & "', '" & dropdcourse2.SelectedValue.ToString & "','" & name.Text & "','" & surname.Text & _
"','" & mobile.Text & "','" & home.Text & "','" & email.Text & "','" & dropdschool.SelectedValue.ToString & "')", MyConn)
Much appreciated.
-
Oct 10th, 2005, 07:30 AM
#5
Fanatic Member
Re: Error on connection open
Are you using Oracle SQL or Access?
I would comment out the your command declaration for starters
Write out the query then run it directly in Query Analyzer for SQL
Try this -
VB Code:
'Dim myCommand As New OleDbCommand("INSERT INTO ApplicantsDetails(IDNumber,Course1,Course2,FirstName, LastName,Mobile,HomeTel,Email,School) VALUES('" & ID_No.Text & "' ,'" & _
' dropdcourse1.SelectedValue.ToString & "', '" & dropdcourse2.SelectedValue.ToString & "','" & name.Text & "','" & surname.Text & _
' "','" & mobile.Text & "','" & home.Text & "','" & email.Text & "','" & dropdschool.SelectedValue.ToString & "')", MyConn)
Response.Write("INSERT INTO ApplicantsDetails(IDNumber,Course1,Course2,FirstName, LastName,Mobile,HomeTel,Email,School)<br>" & _
VALUES('" & ID_No.Text & "'<br>" & _
", '" & dropdcourse1.SelectedValue.ToString & "'<br>" & _
", '" & dropdcourse2.SelectedValue.ToString & "'<br>" & _
", '" & name.Text & "'<br>" & _
", '" & surname.Text & "'<br>" & _
", '" & mobile.Text & "'<br>" & _
", '" & home.Text & "'<br>" & _
", '" & email.Text & "'<br>" & _
", '" & dropdschool.SelectedValue.ToString & "'<br>" & _
")")
Once it's written out you can check that the expected values are there, plus that the datatypes are correct. Only strings should be surrounded by single quotes.
Last edited by aconybeare; Oct 10th, 2005 at 07:32 AM.
Reason: forgot the closing bracket
-
Oct 10th, 2005, 05:03 PM
#6
Thread Starter
Frenzied Member
Re: Error on connection open
HI aconybeare,
Ths for your help. The error was like this:
it didnt accept the word
name.text
and then when I changed it to txtname.text it worked fine. Im posting this for others to know maybe they do the same mistake. Infact I was ready a post of Mendhak to some thread when I realized that was my mistake too.
Thanks Mendhak .
aconybeare Ive never used your kind of approach. If you have some time can you give a short explaination on how to use that pls.
-
Oct 10th, 2005, 05:11 PM
#7
Fanatic Member
Re: Error on connection open
Angelica,
What don't you understand exactly? Have you tried what I posted above, if not try it as it is and see what happens. It should bomb out on the line where you are referencing an invalid control name name.text
This approach just allows you to check the validity of your query before you go sending it to the DB.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|