Question How can I solve this problem?

vb.hallo

New member
Joined
Apr 12, 2011
Messages
1
Location
Malaysia
Programming Experience
Beginner
I cant update my table and it keep coming out this error msg, " Update requires a valid UpdateCommand when passed DataRow collection with modified rows. " the following is my code. Really need some HELP!


Private Sub btnComOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComOrder.Click

DGVRC = Account_Receivable_DatabaseDataGridView.RowCount

If rows = 1 Then
MessageBox.Show("Transaction cannot be processed with no orders", "KDE Centralized Management System (Version 1.0) : Warning", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning)
Else
Dim statusPOSact As Integer = 0 'have confirmed pos ?
Dim stampToGrid As Integer = 0
Do While (stampToGrid = 0)
For num As Integer = 0 To DGVRC - 1
If Account_Receivable_DatabaseDataGridView.Item(0, num).Value = "" Then
Inventory_DatabaseBindingNavigator.AddNewItem.PerformClick()
Inventory_DatabaseBindingNavigator.Refresh()


ab = ""
ac = CStr(DGVRC)

generateZero = 6 - ac.Length
For count As Integer = 1 To generateZero
ab = ab + "0"
Next

'transfer to acc rec
Account_Receivable_DatabaseDataGridView.Item(0, num).Value = ab + CStr(DGVRC) 'orderID
Account_Receivable_DatabaseDataGridView.Item(1, num).Value = Now
Account_Receivable_DatabaseDataGridView.Item(2, num).Value = txtGTotal.Text 'Amount
Account_Receivable_DatabaseDataGridView.Item(3, num).Value = txtMemID.Text 'ID
Account_Receivable_DatabaseDataGridView.Item(4, num).Value = txtMemFName.Text 'Name
Account_Receivable_DatabaseDataGridView.Item(5, num).Value = lblPOS.Text 'TranType




Me.Validate()
Me.Account_Receivable_DatabaseBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me._Club_Management_System__2_DataSet) ' Error at this line
stampToGrid = 1
Exit For

ElseIf num = DGVRC - 1 Then
DGVRC = DGVRC + 1


End If
Next
Loop

Do While (statusPOSact < DataGridView1.RowCount - 1)
For num As Integer = 0 To orderRows - 1

If BillOrder_DatabaseDataGridView.Item(0, orderRows - 1).Value = "" Then
BillOrder_DatabaseBindingNavigator.AddNewItem.PerformClick()
BillOrder_DatabaseDataGridView.Item(5, orderRows - 1).Value = ab + CStr(DGVRC) 'orderID

'generate id

acr = CStr(DGVRC)
generateZero = 5 - acr.Length
zero = ""
For count As Integer = 2 To generateZero
zero = zero + "0"
Next
orderid = zero + CStr(DGVRC)

BillOrder_DatabaseDataGridView.Item(0, orderRows - 1).Value = CStr(orderid) + CStr(statusPOSact + 1)
BillOrder_DatabaseDataGridView.Item(1, orderRows - 1).Value = txtMemID.Text
BillOrder_DatabaseDataGridView.Item(2, orderRows - 1).Value = DataGridView1.Item(0, statusPOSact).Value
BillOrder_DatabaseDataGridView.Item(3, orderRows - 1).Value = DataGridView1.Item(3, statusPOSact).Value
BillOrder_DatabaseDataGridView.Item(4, orderRows - 1).Value = Now

Me.Validate()
Me.BillOrder_DatabaseBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me._Club_Management_System__2_DataSet)

orderRows = orderRows + 1
statusPOSact = statusPOSact + 1
Exit For
ElseIf num = orderRows - 1 Then
orderRows = orderRows + 1
End If
Next
Loop

Me.Validate()
Me.Account_Receivable_DatabaseBindingSource.EndEdit()
Me.Inventory_DatabaseBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me._Club_Management_System__2_DataSet)

MessageBox.Show("Records saved. System will return to main menu")
Me.Dispose()
FormPOS_Report.Show()
'modulePOSReport.Show()
End If
 
For future reference:

1. Please provide meaningful thread titles. The title should give everyone an idea of whether the thread is relevant to them or not so they don't waste their time opening every single thread. It's never difficult to provide a concise summary of the problem.

2. Please post in the most appropriate forum. VS.NET General is for general IDE questions. This thread belongs in VB.NET General or maybe ADO.NET.

3. Please use the Code button in the advanced editor to wrap your code snippets in formatting tags for readability.

As for the question, a TableAdapter will automatically generate an UpdateCommand if the query involves a single table and returns that table's primary key. Your issue is most likely that you haven't created a primary key in the database table.
 
Back
Top