Dhagz03
New member
- Joined
- Jun 8, 2024
- Messages
- 3
- Programming Experience
- 1-3
Good day asking for help.
I'm building a POS System and I always get the error of
Scenario when I scan more than 3 the error is always show.
How to fix error?
My Code :
Thank you and advance.
I'm building a POS System and I always get the error of
ExecuteReader requires an open available Connection. The connection's current state is closed.
Scenario when I scan more than 3 the error is always show.
How to fix error?
My Code :
VB.NET:
Private conString As String = "Provider=Microsoft.ace.oledb.12.0;data source= dzre.accdb"
Private Sub txt_barcode_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt_barcode.KeyPress
If e.KeyChar = ChrW(Keys.Enter) Then
Dim scannedValue As String = txt_barcode.Text.Trim()
If Not String.IsNullOrEmpty(scannedValue) Then
InsertScannedValue(scannedValue)
txt_barcode.Clear()
count_total_price()
load_pos()
End If
e.Handled = True
End If
End Sub
Private Sub InsertScannedValue(value As String)
Dim str As String = "Insert into invoice_sale (is_invoice, is_item_name, is_item_qty, is_item_price, is_item_unit, is_item_id, is_item_date) values(@d0, @d1, @d2, @d3, @d4, @d5, @d6)"
Using connection As New OleDbConnection(conString)
Using cmd As New OleDbCommand(str, connection)
cmd.Parameters.AddWithValue("@d0", lbl_invoice.Text)
cmd.Parameters.AddWithValue("@d1", TextBox3.Text)
cmd.Parameters.AddWithValue("@d2", TextBox1.Text)
cmd.Parameters.AddWithValue("@d3", TextBox4.Text)
cmd.Parameters.AddWithValue("@d4", TextBox5.Text)
cmd.Parameters.AddWithValue("@d5", TextBox2.Text)
cmd.Parameters.AddWithValue("@d6", lbl_date.Text)
Try
connection.Open()
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
If rowsAffected > 0 Then
lblStatus.Text = "Data inserted successfully"
Else
lblStatus.Text = "Failed to insert data"
End If
Catch ex As Exception
lblStatus.Text = "Error: " & ex.Message
Finally
If connection.State = ConnectionState.Open Then
connection.Close()
End If
End Try
End Using
End Using
End Sub
Thank you and advance.
Attachments
Last edited by a moderator: