CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2012

    Question Visual Basic 2010 Help Needed

    i am trying to create a form that lets me add new entries into a database when i click a button. "reference to a non-shared member requires an object reference" is the error that occurs at karateDataSet.Tables("Payments") on line 17 and 22 in the code. any help would be appreciated, thanks.

    Public Class AddNewPayments
        Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
        End Sub
        Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
            Dim newAccount As Integer
            Dim newMember As Integer
            Dim payDate As Date
                newAccount = CInt(txtAccount.Text)
                newMember = CInt(txtMember.Text)
                payDate = DateTimePicker1.Value.Date
                Dim newPaymentsRow As DataRow = karateDataSet.Tables("Payments").NewRow()
                newPaymentsRow("Account") = newAccount
                newPaymentsRow("Member_ID") = newMember
                newPaymentsRow("Payment_Date") = payDate
            Catch ex As Exception
                MessageBox.Show("Only numeric values can be added")
            End Try
        End Sub
    End Class

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: Visual Basic 2010 Help Needed

    Looks like your code overwrites the current line, then adds a new line, which you never fill any fields. Plus, you never SAVE the table INSERT statement. You've skipped a chapter or two

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2009
    NW USA

    Re: Visual Basic 2010 Help Needed

    You are receiving a compile error, not a runtime error. The error has to do with the fact that karateDataSet has not been included in your Form1 class. I don't work with code when building forms so the only way I know to fix this (assuming the dataset has already been created and the Payments table created in the DS) is to drag the karateDataSet component from the Toolbox onto the form.

    I ran the code and it works fine after that.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.