Link to home
Start Free TrialLog in
Avatar of systan
systanFlag for Philippines

asked on

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

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 & "'" & ")"

Open in new window


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 & ")"

Open in new window



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

Open in new window

SOLUTION
Avatar of Rose Babu
Rose Babu
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of systan

ASKER

I solved it, and I gave points to the assisting experts, of which I think another solution.