1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error in connection database

Discussion in 'C#' started by lieweffect, Jun 4, 2006.

  1. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    Once I run the program it give me this error:
    An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

    Here is the code:
    OleDbConnection Conn=new OleDbConnection(ConnString);
    Conn.Open();
    OleDbDataReader dr;
    OleDbCommand dbcom=new OleDbCommand();
    DataSet ds=new DataSet();
    OleDbDataAdapter da=new OleDbDataAdapter();
    da.SelectCommand=new OleDbCommand(Sqlstring,Conn);
    da.Fill(ds);
    dbcom.Connection=(Conn);
    dbcom.CommandText=Sqlstring;
    dr=dbcom.ExecuteReader();

    it say the dbcom is undefined value.
    How to fix it
    Help!Thank Q
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    It looks like you have an error in the SQL query probably.
     
  3. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    So,what should I do and how to fix it.
    Thank Q
     
    Last edited: Jun 5, 2006
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    By correcting the errors in the query.
     
  5. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    May I know how to correct it please?
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    If you can share the query we can definitely look into it.
     
  7. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    Here is the whole program code
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Please dont attach the complete projects as its very difficult to find where the error is and where the query is. I have removed the attached project.

    Please read [thread=168]Before you make a query[/thread].
     
  9. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    Sorry, because I don't know how to find the query as you know I'm the beginner of programming.If I did something please correct me!
     

    Attached Files:

    • db.doc
      File size:
      1.5 KB
      Views:
      7
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Whats the value of Sqlstring when its giving the exception.
     
  11. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    it say the dbcom is undefined value.
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Sqlstring is passed as variable to FillListBox function and so the value of Sqlstring can be determined before hand only and you dont need to be going through the OleDb code.
     
  13. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    If I don't going through the OleDb code. The data will not list at the list box there.
     
  14. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    But to get that all you need is call that function with a string and the error is in the string.
     
  15. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    lieweffect probably you need to concentrate on basics first and get the grasp and then go for database programming in C#.
     
  16. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    Thank Q for your advise coderzone
    Actually the original program is in vb code.
    It can run properly.
    After I convert it into c# follow the c# syntax it cannot run.
    So,may I know which is the mistake from the code
    Thank Q
     
  17. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    The error is in creation of the sql string.
     
  18. lieweffect

    lieweffect New Member

    Joined:
    Apr 20, 2006
    Messages:
    58
    Likes Received:
    0
    Trophy Points:
    0
    Thank Q
    I try to create again
     

Share This Page