[Update notes:]
My desire is that a user adding a new row to a datagridview (DGV) can have this row created in the Access database and be able to create multiple rows and non-synchronous changes for these new rows. The DGV is populated with a data table, and I found that the data set between the DGV and the database is best practice (or at least allows flexibility).
To make changes to several new user new rows, the dataset must be able to retrieve the primary key with automatic increment from the database, and then replenish the DGV with updated key values for new rows. Or at least this is the only way I found this job. The problem is that when I try to add a row to a datatable, it finishes creating three rows instead of one.
[Old post deleted for brevity]
Here's how the DGV first populates and binds to a dataset:
Dim ConMain As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & MasterPath)
Dim ds As New DataSet
Public Sub UniversalFiller(ByVal QueryStringFill As String, ByVal DGV As DataGridView, ByVal AccessDBTableName As String)
If IsNothing(ds.Tables(AccessDBTableName)) Then
Else
ds.Tables(AccessDBTableName).Clear()
End If
ConMain.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & MasterPath
Dim daZZ As New OleDbDataAdapter(QueryStringFill, ConMain)
Try
daZZ.Fill(ds, AccessDBTableName)
DGV.DataSource = ds
DGV.DataMember = AccessDBTableName
DGV.AutoResizeColumns()
Catch ex As Exception
WriteToErrorLog(ex.Message, ex.StackTrace, ex.GetHashCode, ex.Source, ex.ToString)
ds.Clear
MsgBox("There was an error filling the DGV, ds.cleared") 'this is for my notes, not user error'
End Try
End Sub
Update:
I still can not understand this problem. This is called processing DGV.UserAddedRow. I found out that the source code may not be the best way to just add 1 line, but even creating a new line does the same problem:
Dim daZZ As New OleDbDataAdapter(DBSelectQuery, ConMain)
Dim CurrentCellPoint As Point = DGV.CurrentCellAddress
Dim CurrentCellText As String = DGV.CurrentCell.Value.ToString
Dim cmdBldr As New OleDbCommandBuilder(daZZ)
cmdBldr.QuotePrefix = "["
cmdBldr.QuoteSuffix = "]"
MsgBox("1")
Dim DaZZDataRow As DataRow = ds.Tables(DTName).NewRow
MsgBox("2")
DaZZDataRow(CurrentCellPoint.X) = CurrentCellText
MsgBox("3")
ds.Tables(DTName).Rows.Add(DaZZDataRow)
MsgBox("4")
daZZ.InsertCommand = cmdBldr.GetInsertCommand()
MsgBox("5")
daZZ.Update(ds.Tables(DTName))
MsgBox("6")
ds.Tables(DTName).Clear()
daZZ.Fill(ds, DTName)
MsgBox("5")
daZZ.Update(ds.Tables(DTName))
DGV.CurrentCell = DGV(CurrentCellPoint.X, CurrentCellPoint.Y)
- ds.Tables(DTName).Rows.Add(). , .Add(). , 0, 3 . . ds.Tables(DTName).Rows.Add().
, ? / SQL, , , 1. , MsgBox 3 .
, InsertAt :
ds.Tables(DTName).Rows.InsertAt(DaZZDataRow, CurrentCellPoint.Y)
ds.Tables(DTName).Rows.Add() 3 . DB Access .
, VS2012 Project . , , , . , .