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()
Printable View
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()
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
Hmmm it seems you've moved the goal posts??
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.
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.
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.
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.