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.
Code:
Public Class AddNewPayments
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
Payments.Show()
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
Try
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
karateDataSet.Tables("Payments").Rows.Add(newPaymentsRow)
Catch ex As Exception
MessageBox.Show("Only numeric values can be added")
End Try
End Sub
End Class
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
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.