Hi guys,
First of all, i'd like to tell you that i've gone mad with this issue not for hours, but for days long now, and i've gone around dozens and dozens of web forums & pages, googling and so on to understand from where this issue is arising within my code.
Let me give you the exact moment this issue is happening.
I'm working on a membership application for month now, and suddenly some weeks ago i've stumbled on this issue.
- After adding a record to my dataset:
The database is SQLite db.
Here are some code part of the application. A lot is missing as i can't post all of the app code of course.
I have a SQLite db, a datagridview binded the datatable, and a dataset of course.
Hopefully, any one of you could point me to the right direction...
Oh i've forgot to explaint that the datagridview has two unbounded columns: "ColumnImageStatus" and "ColumnImageClosed"
These unbounded columns are here to display a small image bitmap, depending on the data contained at the row("Status") and row("Closed") of the dataset.
Please forgive me if i've forgot/mistyped anything below.
I know this kind of issue has been covered many times, but i'm loosing hope..
Thank you so much for all your help,
Regards,
In the main form,
LOADING & SAVING DB (DB_Update Class)
The part where i ADD the ROW:
The part where i DELETE the data
First of all, i'd like to tell you that i've gone mad with this issue not for hours, but for days long now, and i've gone around dozens and dozens of web forums & pages, googling and so on to understand from where this issue is arising within my code.
Let me give you the exact moment this issue is happening.
I'm working on a membership application for month now, and suddenly some weeks ago i've stumbled on this issue.
- After adding a record to my dataset:
- if i try to delete the record right after i've added it i'm getting the issue.
- if i close the application (it saves the db before closing), and restart it, i can safely delete the record.
- i can add as many records as i want, i can safely close the app.
The database is SQLite db.
Here are some code part of the application. A lot is missing as i can't post all of the app code of course.
I have a SQLite db, a datagridview binded the datatable, and a dataset of course.
Hopefully, any one of you could point me to the right direction...
Oh i've forgot to explaint that the datagridview has two unbounded columns: "ColumnImageStatus" and "ColumnImageClosed"
These unbounded columns are here to display a small image bitmap, depending on the data contained at the row("Status") and row("Closed") of the dataset.
Please forgive me if i've forgot/mistyped anything below.
I know this kind of issue has been covered many times, but i'm loosing hope..
Thank you so much for all your help,
Regards,
In the main form,
Code:
Public MonDataSet As New DataSet("Teresdat")
Public bindingsourceDGV_freebies As New BindingSource
Public tblsl_Teresdat_freebies As DataTable
'FORMLOAD
Private Sub MainManager_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DB_Update.load_SQLite_db()
'Binding du DGV_Freebies
Me.bindingsourceDGV_freebies.DataSource = MonDataSet.Tables("Teresdat_freebies")
DGV_Freebies.DataSource = Me.bindingsourceDGV_freebies
End sub
Private Sub DGV_Freebies_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles DGV_Freebies.DataBindingComplete
'Deselection de la premi�re ligne
DGV_Freebies.ClearSelection()
DGV_Freebies.CurrentCell = Nothing
' Put each of the columns into programmatic sort mode.
For Each column As DataGridViewColumn In DGV_Freebies.Columns
column.SortMode = DataGridViewColumnSortMode.Programmatic
Next
Dim StatusImageColumn As DataGridViewImageColumn = DGV_Freebies.Columns("ColumnImageStatus")
Dim ClosedImageColumn As DataGridViewImageColumn = DGV_Freebies.Columns("ColumnImageClosed")
With StatusImageColumn
.DefaultCellStyle.NullValue = Nothing
'.DataPropertyName = "Status"
End With
With ClosedImageColumn
.DefaultCellStyle.NullValue = Nothing
'.DataPropertyName = "Closed"
End With
'Colonnes invisibles
DGV_Freebies.Columns("ColumnID").Visible = False 'ID
DGV_Freebies.Columns("ColumnuserID").Visible = False 'userID
DGV_Freebies.Columns("ColumnStatus").Visible = False 'Status
DGV_Freebies.Columns("ColumnClosed").Visible = False 'Closed
Dim StatusDelivered As Bitmap
Dim StatusUnDelivered As Bitmap
StatusDelivered = My.Resources.hand_stop
StatusUnDelivered = My.Resources.hand_deliver
Dim ClosedClosed As Bitmap
Dim ClosedOpen As Bitmap
ClosedClosed = My.Resources.Lock_20_closed
ClosedOpen = My.Resources.Lock_20_open
For i = 0 To DGV_Freebies.RowCount - 1
Dim Status As Boolean = CBool(DGV_Freebies.Rows(i).Cells("ColumnStatus").Value)
If Status = True Then
DGV_Freebies.Rows(i).Cells("ColumnImageStatus").Value = StatusDelivered
Else
DGV_Freebies.Rows(i).Cells("ColumnImageStatus").Value = StatusUnDelivered
End If
Dim Closed As Boolean = CBool(DGV_Freebies.Rows(i).Cells("ColumnClosed").Value)
If Closed = True Then
DGV_Freebies.Rows(i).Cells("ColumnImageClosed").Value = ClosedClosed
Else
DGV_Freebies.Rows(i).Cells("ColumnImageClosed").Value = ClosedOpen
End If
If Status = True And Closed = True Then
DGV_Freebies.Rows(i).DefaultCellStyle.BackColor = Color.DarkGray
DGV_Freebies.Rows(i).DefaultCellStyle.ForeColor = Color.Black
Dim font As New Font(DGV_Freebies.DefaultCellStyle.Font.FontFamily, 8, FontStyle.Regular)
DGV_Freebies.Rows(i).DefaultCellStyle.Font = font
ElseIf Status = True And Closed = False Then
DGV_Freebies.Rows(i).DefaultCellStyle.BackColor = Color.Crimson
DGV_Freebies.Rows(i).DefaultCellStyle.ForeColor = Color.WhiteSmoke
Dim font As New Font(DGV_Freebies.DefaultCellStyle.Font.FontFamily, 8, FontStyle.Bold)
DGV_Freebies.Rows(i).DefaultCellStyle.Font = font
ElseIf Status = False And Closed = False Then
DGV_Freebies.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue
End If
Next
End Sub
Code:
'LOADING DB
Shared Sub load_SQLite_db()
Dim strConnexion As String = "Data Source=" + path + "\DB\Teresdat.db; Version=3"
Dim myConnexion As SQLiteConnection = New SQLiteConnection(strConnexion)
Try
myConnexion.Open()
Dim Requetesl_Teresdat_freebies As String = "SELECT * from Teresdat_freebies"
Dim SQLite_Commandesl_ceres_freebies As New SQLiteCommand(Requetesl_Teresdat_freebies, myConnexion)
Adaptateursl_Teresdat_freebies = New SQLiteDataAdapter(SQLite_Commandesl_Teresdat_freebies)
Adaptateursl_Teresdat_freebies.FillSchema(MainManager.MonDataSet, SchemaType.Source, "Teresdat_freebies")
Adaptateursl_Teresdat_freebies.Fill(MainManager.MonDataSet, "Teresdat_freebies")
MainManager.tblsl_Teresdat_freebies = MainManager.MonDataSet.Tables("Teresdat_freebies")
myConnexion.Close()
Catch ex As Exception
End Try
End Sub
'SAVING
Shared Sub Save_DB()
Try
Dim objCommandBuilder7 As New SQLiteCommandBuilder(Adaptateursl_Teresdat_freebies)
Adaptateursl_Teresdat_freebies.Update(MainManager.MonDataSet, "Teresdat_freebies")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
The part where i ADD the ROW:
Code:
'Ajout de l'op�ration dans le tableau des freebies Transactions
Dim newProductsRow As DataRow = MonDataSet.Tables("Teresdat_freebies").NewRow()
newProductsRow("SLuserID") = Selected_userID
newProductsRow("Date") = DateTime.Now.ToString()
newProductsRow("Username") = selected_username
newProductsRow("Freebie") = CBOX_Freebie_product.Text
newProductsRow("Cost") = LBL_Freebie_Cost.Text
newProductsRow("Status") = False
newProductsRow("Closed") = False
newProductsRow("ProductID") = FreebieID
'Ajout de la ligne dans le dataset -> Freebies
MonDataSet.Tables("Teresdat_freebies").Rows.Add(newProductsRow)
'Raffraichissement du DGV
DGV_Freebies.EndEdit()
DGV_Freebies.Refresh() 'Je raffraichis l'affichage
'Synchronization du dataset avec MySQL
DB_Update.Save_DB()
The part where i DELETE the data
Code:
Private Sub VoidLine(ByVal db_row_ID As Integer, ByVal sluserid As Integer, ByVal username As String, ByVal freebiepoints As Integer, ByVal freebieproductname As String)
Dim rows() As DataRow = tblsl_Teresdat_freebies.Select("ID = '" & db_row_ID & "'")
If rows.Count > 0 Then
'Suppression de la ligne dans la liste des transactions
rows(0).Delete()
End If
DGV_Freebies.EndEdit()
DGV_Freebies.Refresh()
'updating DB
DB_Update.Save_DB()
End Sub