Avatar of systan
systan
Flag 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

Visual Basic.NET

Avatar of undefined
Last Comment
systan

8/22/2022 - Mon
SOLUTION
Rose Babu

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
systan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
systan

ASKER
I solved it, and I gave points to the assisting experts, of which I think another solution.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck