How to add data row to table?

Joined
Dec 10, 2007
Messages
18
Location
Florida
Programming Experience
Beginner
Hello all, I am trying to add a data row to a data table, but so far I have been unsuccessful. Here is the code I have:

VB.NET:
Dim newSalesRow As DataRow = MPS_DataSet.Tables("Sales").NewRow()

newSalesRow("invoiceNumber") = OrderNumberInteger.ToString

MPS_DataSet.Tables("Sales").Rows.Add(newSalesRow)

        Me.Validate()
        Me.SalesBindingSource.EndEdit()
        Me.SalesTableAdapter.Update(MPS_DataSet)

I have a bound combo box on the form, just to check to see if the data is correctly being added to the Sales table. However, I am only receiving a single digit integer after this code runs in the combo box. The integer stored in OrderNumberInteger is 6 digits in length.

Also, I have Copy to Output Directory property set to COpy if Newer. (For the MDF file)

When I run the terminate and then run the program the single digit integer (which is incorrect) that was stored in the combo box is empty.

Note: I have this code at load:
VB.NET:
       'fills sales tables
        Me.SalesTableAdapter.Fill(Me.MusicPlusInventorySQLDataSet.Sales)

            'setup sales binding source
            With SalesBindingSource
                .DataSource = MPS_DataSet
                .DataMember = "Sales"
            End With

            'Bind the InvoiceNumberComboBox to see if working
            With Me.InvoiceNumberComboBox
                .DataSource = SalesBindingSource
                .DisplayMember = "invoiceNumber"
            End With

Help would be greatly appreciated.
 
Hello all, I am trying to add a data row to a data table, but so far I have been unsuccessful. Here is the code I have:

VB.NET:
Dim newSalesRow As DataRow = MPS_DataSet.Tables("Sales").NewRow()

newSalesRow("invoiceNumber") = OrderNumberInteger.ToString

MPS_DataSet.Tables("Sales").Rows.Add(newSalesRow)

        Me.Validate()
        Me.SalesBindingSource.EndEdit()
        Me.SalesTableAdapter.Update(MPS_DataSet)
OK, the idea of making TYPED datatables is that you use them in typed, not untyped fashion:

MPS_DataSet.Sales.AddSalesRow(OrderNumberInteger.ToString(), ...other params...)

or:

Dim ro as DataSetNameSpace.SalesRow = MPS_DataSet.Sales.NewSalesRow()
ro.invoiceNumber = OrderNumberInteger.ToString()
MPS_DataSet.Sales.AddSalesRow(ro)


I have a bound combo box on the form, just to check to see if the data is correctly being added to the Sales table. However, I am only receiving a single digit integer after this code runs in the combo box. The integer stored in OrderNumberInteger is 6 digits in length.
If OrdernumberInteger is some kind of default key and the user fills in the rest, I tend to do:

myDataSetInstance.Sales.InvoiceNumberColumn.DefaultValue = OrderIntegerNumber.ToString()
myBindingSourceBoundToTheDataTable.AddNew()

Also, I have Copy to Output Directory property set to COpy if Newer. (For the MDF file)
That affects the copying of the database file, it's nothing to do with a dataset, and a dataset is not a database

Note: I have this code at load:
VB.NET:
       'fills sales tables
        Me.SalesTableAdapter.Fill(Me.MusicPlusInventorySQLDataSet.Sales)

            'setup sales binding source
            With SalesBindingSource
                .DataSource = MPS_DataSet
                .DataMember = "Sales"
            End With

            'Bind the InvoiceNumberComboBox to see if working
            With Me.InvoiceNumberComboBox
                .DataSource = SalesBindingSource
                .DisplayMember = "invoiceNumber"
            End With
I dont recall ever writing code to link bindingsources to datatables myself; the designer does that. Perhaps youre being too suspicious and you should just go with the flow a little more. Read the DW2 link in my sig, section "creating a simple data app"

Help would be greatly appreciated.

Well, youre doing something silly, but I'm not sure what..

Me.SalesTableAdapter.Fill(Me.MusicPlusInventorySQLDataSet.Sales) 'okay you fill the sales table correctly using the adapter (all records; is this wise?)

SalesBindingSource.DataSource = MPS_DataSet 'huh? where did mps dataset come from? sales binding source should bind to the sales table you just filled


I would ask what goal youre trying to achieve..but first; do you know? :)
 

Latest posts

Back
Top