Results 1 to 7 of 7

Thread: Error on connection open

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    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.

  2. #2
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: Error on connection open

    I think you're missing a closing bracket on the end of your declaration

    should read -

    VB Code:
    1. ...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

  3. #3
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: Error on connection open

    Hmmm it seems you've moved the goal posts??

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    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:
    1. Dim myCommand As New OleDbCommand("INSERT INTO ApplicantsDetails(IDNumber,Course1,Course2,FirstName, LastName,Mobile,HomeTel,Email,School) VALUES('" & ID_No.Text & "' ,'" & _
    2.             dropdcourse1.SelectedValue.ToString & "', '" & dropdcourse2.SelectedValue.ToString & "','" & name.Text & "','" & surname.Text & _
    3.             "','" & mobile.Text & "','" & home.Text & "','" & email.Text & "','" & dropdschool.SelectedValue.ToString & "')", MyConn)

    Much appreciated.

  5. #5
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    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:
    1. 'Dim myCommand As New OleDbCommand("INSERT INTO ApplicantsDetails(IDNumber,Course1,Course2,FirstName, LastName,Mobile,HomeTel,Email,School) VALUES('" & ID_No.Text & "' ,'" & _
    2. '            dropdcourse1.SelectedValue.ToString & "', '" & dropdcourse2.SelectedValue.ToString & "','" & name.Text & "','" & surname.Text & _
    3. '            "','" & mobile.Text & "','" & home.Text & "','" & email.Text & "','" & dropdschool.SelectedValue.ToString & "')", MyConn)
    4.  
    5. Response.Write("INSERT INTO ApplicantsDetails(IDNumber,Course1,Course2,FirstName, LastName,Mobile,HomeTel,Email,School)<br>" & _
    6. VALUES('" & ID_No.Text & "'<br>" & _
    7.     ", '" & dropdcourse1.SelectedValue.ToString & "'<br>" & _
    8.     ", '" & dropdcourse2.SelectedValue.ToString & "'<br>" & _
    9.     ", '" & name.Text & "'<br>" & _
    10.     ", '" & surname.Text & "'<br>" & _
    11.     ", '" & mobile.Text & "'<br>" & _
    12.     ", '" & home.Text & "'<br>" & _
    13.     ", '" & email.Text & "'<br>" & _
    14.     ", '" & dropdschool.SelectedValue.ToString & "'<br>" & _
    15. ")")

    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

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    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.

  7. #7
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    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
  •  



Click Here to Expand Forum to Full Width