Database connection question

Results 1 to 2 of 2

Thread: Database connection question

  1. #1
    Join Date
    Dec 1969

    Default Database connection question

    I&#039;m new to ASP.Net and I&#039;m attempting to make a connection to my database as follows:<BR><BR>sub Page_Load<BR> dim dbconn,sql,dbcomm,dbread<BR> dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.mappath("db1.mdb"))<BR> dbconn.Open()<BR> <BR> sql="SELECT * FROM tblPropSerials"<BR> dbcomm=New OleDbCommand(sql,dbconn)<BR> <BR> dbread=dbcomm.ExecuteReader()<BR> tblPropSerials.DataSource=dbread<BR> tblPropSerials.DataBind()<BR> <BR> dbread.Close()<BR> dbconn.Close()<BR> end sub<BR><BR><BR>My error message is:<BR><BR>escription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.<BR><BR>Exception Details: System.NullReferenceException: Object variable or With block variable not set.<BR><BR>Source Error:<BR><BR>Line 10: dbcomm=New OleDbCommand(sql,dbconn)<BR>Line 11: dbread=dbcomm.ExecuteReader()<BR>Line 12: tblPropSerials.DataSource=dbread<BR>Line 13: tblPropSerials.DataBind()<BR>Line 14: dbread.Close()<BR><BR><BR>Source File: c:inetpubwwwrootNewFile.aspx Line: 12<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Database connection question

    I think you need to instantiate a new OleDataReader for the "dbread" variable.<BR><BR>IE:<BR>Dim dbread As OleDataReader = dbcomm.ExecuteReader()<BR><BR>That might do it. remove the "Dim dbread" at the top of the code as well.<BR><BR>Buzz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts