troubleshooting Question

sql insert not saving data (HOW TO INSERT WITHOUT USING PARAMETER)

Avatar of systan
systanFlag for Philippines asked on
Visual Basic.NET
3 Comments2 Solutions598 ViewsLast Modified:
The sample1 result of that is:
Dim NScript As String = "insert into expences(dtime,expencefor,cash,byemp) values ('Jan 2012','BILLS','38.50','JOHN')"
sample1:
Dim NScript As String = "insert into expences(dtime,expencefor,cash,byemp) values (" & "'" & dtnow.ToString & "'" & "," & "'" & txtexp & "'" & "," & "'" & txtcash & "'" & "," & "'" & Txtexpences.Tag.ToString & "'" & ")"

The sample2 result is this:(withou single quatation)
Dim NScript As String = "insert into expences(dtime,expencefor,cash,byemp) values (Jan 2012,BILLS,38.50,JOHN)"
sample2:(withou single quatation)
        
Dim NScript As String = "insert into expences(dtime,expencefor,cash,byemp) values (" & dtnow.ToString & "," & txtexp & "," & txtcash & "," & Txtexpences.Tag.ToString & ")"


The above is for saving record from tcpClient network, but it doesn't insert.
Where's the correct script?
I'm using this function, whats wrong with it?
usage:
SaveSendReceived(Nscript, "Network")
    
Private Sub SaveSendReceivedExpences(ByVal script As String, ByVal culture As String)
        Dim sc As New SQLiteCommand(script, mycon)
''//THIS SAVED IN LOCAL SERVER DATABASE FILE
        If culture.Equals("local") Then
            Dim dtnow As DateTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt")
            sc.Parameters.Add("$dt", DbType.DateTime).Value = dtnow
            sc.Parameters.Add("$exp4", DbType.String).Value = Txtexpences.Text
            sc.Parameters.Add("$cas", DbType.Decimal).Value = txtcashexpences.Text
            sc.Parameters.Add("$byempl", DbType.String).Value = Txtexpences.Tag.ToString
            MessageBox.Show("SAVING TO LOCAL SERVER")
        Else
           
            'Dim i As Integer = script.IndexOf("values")
            'Dim items As String = script.Substring(i + 6, Len(script) - (i + 6)).TrimStart(" ")
            'items = items.TrimStart("(")
            'items = items.TrimEnd(")")
            'Dim value(items.Split(",").Length) As String
            'Dim x As Integer = 0
            'For Each item As String In items.Split(",")
            '    value(x) = item
            '    MessageBox.Show(value(x).ToString)
            '    i += 1
            'Next

''//DISABLED BECAUSE IT DOESN'T SAVED ANYTHING
            'sc.Parameters.Add(New SQLiteParameter("dtime", value(0)))
            'sc.Parameters.Add(New SQLiteParameter("expencefor", value(1)))
            'sc.Parameters.Add(New SQLiteParameter("cash", Convert.ToDecimal(value(2))))
            'sc.Parameters.Add(New SQLiteParameter("byemp", value(3)))

            'sc.Parameters.Add("$value(0)", DbType.DateTime).Value = value(0)
            'sc.Parameters.Add("$value(1)", DbType.String).Value = value(1)
            'sc.Parameters.Add("$value(2)", DbType.Decimal).Value = Convert.ToDecimal(value(2))
            'sc.Parameters.Add("value(3)", DbType.String).Value = value(3)
            MessageBox.Show("SAVING FROM NETWORK")
        End If
        sc.ExecuteNonQuery()
        sc.Parameters.Clear()
        sc.Dispose()
    End Sub
ASKER CERTIFIED SOLUTION
systan

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros