Hello,
I've the following code to insert a record into an MS Access database when clicking on Button1:
When I save one record, the DataGrid gets refreshed with the latest data;
When I save another record, the DataGrid repeats all the records again!
Can annyone help please?
Thanks in advance,
João Pinto
I've the following code to insert a record into an MS Access database when clicking on Button1:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=""C:\Programaçao\Visual Basic\Inapal\ReportIt\ReportIt.mdb"";"
con.Open()
sSQL = "SELECT * FROM [Scrap]"
da = New OleDb.OleDbDataAdapter(sSQL, con)
da.Fill(ds, "Scrap")
Dim dsNR As DataRow
Dim cb = New OleDb.OleDbCommandBuilder(da)
dsNR = ds.Tables("Scrap").NewRow
dsNR.Item("Tipo_Peça") = ScrapCombo.SelectedValue
dsNR.Item("Qtd") = Qtdfield.Text
ds.Tables("Scrap").Rows.Add(dsNR)
da.Update(ds, "Scrap")
DataGrid.DataSource = ds
DataGrid.DataMember = "Scrap"
con.Close()
End Sub
When I save one record, the DataGrid gets refreshed with the latest data;
When I save another record, the DataGrid repeats all the records again!
Can annyone help please?
Thanks in advance,
João Pinto