Insert statement loging in MYSQL database


simonwachira

Recommended Posts

I want to insert a row in a table named incoming_sms

The code is as follows:

global dbase

global qr

private string SMSmessage

private string SMSsender

private string Tdate

private string Ttime

dbase = db.open("grant_ecoupon")

qr = db.Query(dbase, "INSERT INTO incoming_sms (sms_body_1,sender_number,sms_date,sms_Time) VALUES ('SMSmessage','SMSsender,'Tdate','Ttime')")

db.CloseQuery(qr)

db.Close(dbase)

The code runs ok but inserts into the datadase ,SMSmessage ,SMSsender ,Tdate and Ttime instead of the strings in the variables

Please tell me what the correct syntax is for an insert SQL query

Note: in mysql table all the datatypes are varchar

Link to comment
Share on other sites

First things first: use db.execute() not db.Query(). db.query() and db.queryToClass() should only really be used for the SELECT statement. All other SQL statements should use execute() (and don't need to call closeQuery()).

But, as for your question, you need to build the string using concatenation, which in DAQFactory is just +, so:

db.Execute(dbase, "INSERT INTO incoming_sms (sms_body_1,sender_number,sms_date,sms_Time) VALUES ('" + SMSmessage + "','" + SMSsender + "','" + Tdate + "','" + Ttime + "' + )")

This, by the way, has nothing to do with database work, but is true whenever you want to insert variables into a string (and by the way, is true for just about any programming language out there, though the syntax for concatenation might be slightly different)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.