I have a form named FrmInvoice. It has a datagridview witch populate data from following code on form load event.
The Button Save has following code
I have a another form named as FrmAdd which have text boxes as TxtItems, TxtQty, TxtRate, TxtAmount and a Button OK. For adding rows to datagridview to FrmInvoice. the code is
The row is added to the datagridview but when Save Button is pressed in FrmInvoice Form, the message is shown as updated, no exception is thrown. When I check by loading form again, it is not added to the database.
Any Alternate code for this ?
Thanks
-
VB.NET:
Try
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Access\Sale.accdb")
'Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM TblSale", con)
con.Open()
myDA = New OleDbDataAdapter(cmd)
'Automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "TblSale")
DataGridView1.DataSource = myDataSet.Tables("TblSale").DefaultView
DataGridView1.ColumnHeadersVisible = False
con.Close()
con = Nothing
Catch ex As Exception
MsgBox("Error", ex.Message)
End Try
VB.NET:
Me.Validate()
Me.myDA.Update(Me.myDataSet.Tables("TblSale"))
Me.myDataSet.AcceptChanges()
MessageBox.Show("Updated.")
Me.Close()
VB.NET:
Dim dt As DataTable = CType(FrmInvoice.DataGridView1.DataSource, DataView).Table
Dim drToAdd As DataRow = dt.NewRow
drToAdd("Items") = TxtItems.Text
drToAdd("Qty") = Convert.ToInt32(TxtQty.Text)
drToAdd("Rate") = Convert.ToDecimal(TxtRate.Text)
drToAdd("Amount") = Convert.ToDecimal(TxtAmount.Text)
dt.Rows.Add(drToAdd)
dt.AcceptChanges()
TxtItems.Focus()
Any Alternate code for this ?
Thanks
-