Click to See Complete Forum and Search --> : please help! DAO project


snoopy22
July 21st, 2003, 06:58 AM
when i run my program the it says:
"syntax error in INSERT INTO statement"


CString filter;
CString s="/";


NewFilter MyDlg;
MyDlg.DoModal();
filter=MyDlg.m_IP+s+MyDlg.m_Protocol+s+MyDlg.m_text +s+MyDlg.m_Start+s+MyDlg.m_End;
CDaoDatabase db;
CDaoRecordset recset(&db);
db.Open("DataBaseAdo.mdb"); // Open Clients.MDB
recset.Open(AFX_DAO_USE_DEFAULT_TYPE,
"SELECT * FROM Filter",0);
here it stuck-->db.Execute("INSERT INTO Filter(m_Filter);");

recset.AddNew();
recset.SetFieldValue("Filter","filter");
recset.Update();

Wtower
July 21st, 2003, 07:22 AM
Dear snoopy22,

basically, you dont help us understand what are some of your definitions. To begin with, I guess that Filter is a table in your .mdb database. Also, filter is a CString, fine. What on earth is m_Filter though? :) Maybe your answer is there.

1) If m_Filter is a CString, you should then rewrite that statement as:

db.Execute("INSERT INTO Filter(" + m_Filter + ");");

2. I am not absolutely convinved with the sql statement. The correct syntax is:

INSERT INTO target [(field1[, field2[, ...]])] [IN externaldatabase]
SELECT [source.]field1[, field2[, ...]
FROM tableexpression

for multiple-record insertion, or

INSERT INTO target [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...])

for single record.

3. Why do you want to add a record like that instead of using a simple AddNew(), as you do one line later?

4. If you want to use AddNew() eventually, you can use CanAppend() to check if your recordset is appendable prior to AddNew().

5. Try moving on to OLE DB or sth, if you are using vc++7, dao is an obsolete tech.

Maybe I didnt read very carefully and missed something, but I hope it was helpful!

Regards,

Wtower

snoopy22
July 21st, 2003, 05:06 PM
thanks a lot man, i've just noticed my mistake, there the "excute" was redundant. now it's working.
thanks again...