tags:

views:

94

answers:

1

I have table which is connected to datagridview and I would like to enter new data by using text boxes. I have following code but it gives me error. Will be appreciated if you help me. Error Message is : Use the "new" keyword to create an object instance

                Dim meter As DataTable = Me.DataSet1.Tables.Item("tblmeters")
                Dim row As DataRow = meter.NewRow()
                row.Item("No") = Me.txtno.Text
                row.Item("Turnover") = Me.txtturnover.Text
                row.Item("Total Win") = Me.txttotalwin.Text
                row.Item("Games Played") = Me.txtgamesplayed.Text
                row.Item("Credit In") = Me.txtcreditin.Text
                row.Item("Bill In") = Me.txtbillin.Text
                row.Item("Hand Pay") = Me.txthandpay.Text
                row.Item("Date") = DateTime.Today.ToShortDateString
                meter.Rows.Add(row)
                Me.TblMeterTableAdapter.Update(Me.DataSet1.tblMeter)
                meter.AcceptChanges()
+1  A: 

Looks like Me.DataSet1.Tables.Item("tblmeters") returns Nothing. Make sure that DataSet1 indeed contains table tblmeters.

Anton Gogolev
That's the only thing I could think of, but coming from a C# background I would have expected a null reference exception.
ChrisF
What a stupid I am. You were right Anton. table name was tblmeterThaks for helping me.
Hakan