Hi,
I was trying to inserting data from a listbox by using PrepareSqlStatement,
the code is running without error, but the data is not inserting.
If mDb.Connect Then
mIsConnected = True
Window1.l_status.Text = "Connected to Schyzosoft CubeSQL"
Else
MsgBox("Connection failed: " + mDb.ErrorMessage)
Return
End If
Dim rowCount As Integer = Window1.ListBox4.ListCount
For i As Integer = 0 To rowCount - 1
Dim Tgl As String = Window1.L_Date.Text
Dim Jam As String = Window1.LD_Time.Text
Dim chk_id As String = Window1.L_chkid.Text
Dim code_item As String = Window1.ListBox4.Cell(i, 1)
Dim Item_name As String = Window1.ListBox4.Cell(i, 2)
Dim Qty As String = Window1.ListBox4.Cell(i, 3)
Dim harga As String = Window1.ListBox4.Cell(i, 4)
Dim Diskon As String = Window1.ListBox4.Cell(i, 5)
Dim total As String = Window1.ListBox4.Cell(i, 6)
Dim guest As String = Window1.L_guest.Text.Trim
Dim member As String = Window1.L_member.Text.Trim
Dim payment_type As String = wPayment.Title
Dim waiter As String = Window1.L_waiter.Text + " | " + Window1.L_nik.Text.Trim
Dim mail As String = Window1.l_mail.Text.Trim
Dim hp As String = Window1.l_hp.Text.Trim
Dim aa, bb, cc As String
Dim fdz As FolderItem
Dim tisx As TextInputStream
fdz = GetFolderItem("shop")
If fdz <> Nil And fdz.Exists Then
tisx = TextInputStream.Open(fdz)
aa = tisx.ReadLine.Trim
tisx.Close
End If
bb = Lowercase(aa)
cc = bb + "_report"
Dim sql As String = "INSERT INTO " + cc + " (date, Jam, chk_id, code_item, nama_item, qty, harga, diskon, total, customer, no_member, payment_type, waiter, email, hp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
Dim ps As MySQLPreparedStatement = mDb.Prepare(sql)
ps.BindType(0, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' Tgl
ps.BindType(1, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' Jam
ps.BindType(2, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' chk_id
ps.BindType(3, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' code_item
ps.BindType(4, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' Item_name
ps.BindType(5, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' Qty
ps.BindType(6, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' harga
ps.BindType(7, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' Diskon
ps.BindType(8, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' total
ps.BindType(9, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' guest
ps.BindType(10, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' member
ps.BindType(11, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' payment_type
ps.BindType(12, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' waiter
ps.BindType(13, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' mail
ps.BindType(14, MySQLPreparedStatement.MYSQL_TYPE_STRING) ' hp
ps.Bind(0, Tgl)
ps.Bind(1, Jam)
ps.Bind(2, chk_id)
ps.Bind(3, code_item)
ps.Bind(4, Item_name)
ps.Bind(5, Qty)
ps.Bind(6, harga)
ps.Bind(7, Diskon)
ps.Bind(8, total)
ps.Bind(9, guest)
ps.Bind(10, member)
ps.Bind(11, payment_type)
ps.Bind(12, waiter)
ps.Bind(13, mail)
ps.Bind(14, hp)
// Debug
System.DebugLog("SQL: " + sql)
System.DebugLog("Values: " + Tgl + ", " + Jam + ", " + chk_id + ", " + code_item + ", " + Item_name + ", " + Qty + ", " + harga + ", " + Diskon + ", " + total + ", " + guest + ", " + member + ", " + payment_type + ", " + waiter + ", " + mail + ", " + hp)
Try
ps.SQLExecute
If mDb.Error Then
System.DebugLog("Error: " + mDb.ErrorMessage)
MsgBox("Error: " + mDb.ErrorMessage)
Else
System.DebugLog("Insert successful")
End If
Catch error As RuntimeException
MsgBox("Error: " + error.Message)
System.DebugLog("Exception: " + error.Message)
End Try
Next
mDb.Close
how to debug, to find the mistake.
thanks
arief
5 posts - 3 participants