Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

OLEdb connection

Back to Forum: Tech Off
  • User profile image
    melt33

    I can't find the problem with this code:


    Sub btnAdd_Click(sender As Object, e As EventArgs)

        Dim myConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwroot\docproj\Supported Databases in Lotus Notes.mdb")
        Dim dbaData As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [TBL_DATABASE]", myConn)
        dim myDS as New System.Data.DataSet()
        dim tbldb as System.Data.DataTable
        dim tblRow as System.Data.DataRow
        dim test as string

        myConn.open()
        dbaData.fill(myDS)

        tbldb = myDS.Tables("TBL_DATABASE")

        tblRow = tbldb.NewRow()

        tblRow("DATABASE_NAME") = txtDataName.text
        tblRow("DATABASE_GROUP") = txtDataGroup.text
        tblRow("DATABASE_GROUP_LOCATION") = txtGroupLoc.text
        tblRow("DATABASE_LOCATION") = txtDataLoc.text
        tblRow("DATABASE_PURPOSE") = txtDataPurp.text
        tblRow("DATABASE_OTHER_NOTES") = txtDataOther.text

        tbldb.Rows.Add(tblrow)

        dbaData.update(myDS)

        myConn.close()

        end if
    End Sub


    The Error:
    System.NullReferenceException: Object reference not set to an instance of an object.

    At line:
    Line 33:         tblRow = tbldb.NewRow()


    I have figured out that tbldb object is Null.  The actual problem seems to be at:

    tbldb = myDS.Tables("TBL_DATABASE")

    msDS isn't null but it won't set the table. 


    JD


  • User profile image
    Red5

    Check the value of myDS.Tables(0).TableName
    It's probably something like "DataSet1"

  • User profile image
    melt33

    Red5 wrote:
    Check the value of myDS.Tables(0).TableName
    It's probably something like "DataSet1"


    Red5,

    I've mad it that far.  Now it is giving me the error:

    System.InvalidOperationException: Update requires a valid InsertCommand when passed DataRow collection with new rows.

    At line:

    Line 61:         dbaData.update(myDS)

    This was supose to be a simple little project.  So much for that.

    Thanks for any help any one gives!!!

    JD

  • User profile image
    SimonJ

    I think you need to check that the DataAdaptor has an InsertCommand and that that InsertCommand has a valid CommandText property, etc.

    SimonJ

  • User profile image
    Red5

    I concur

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.