syntax for passing parameter data at execution time in executesql

// Open the database
database.Open(NULL,false,false,sDsn);

// Allocate the recordset
CRecordset recset( &database );

CString text;
//GetDlgItem(IDC_EDIT1)->GetWindowTextW(text);
m_CatID.GetWindowTextW(text);
text.Format(_T("%d"), x);

// insert data
recset.m_pDatabase->BeginTrans();

//recset.m_pDatabase->ExecuteSQL(L"INSERT INTO Categories (CatID,Category) VALUES('659','gfcgfv')");
recset.m_pDatabase->ExecuteSQL(L"INSERT INTO Categories (CatID) VALUES(?)",x);
if(recset.m_pDatabase->CommitTrans())
TRACE("Transaction Commited\n");
else
TRACE("Error in CommitTrans\n");

// Build the SQL statement for displaying records
SqlString = "SELECT CatID, Category ""FROM Categories";

// Execute the query
recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);
// Reset List control if there is any data
ResetListControl();



Getting error at
ExecuteSQL(L"INSERT INTO Categories (CatID) VALUES(?)",x);
error: Too many arguments in function call
Did you bother to check the documentation for the call?
From: http://msdn.microsoft.com/en-us/library/67cze9b7(v=vs.80).aspx
 
void ExecuteSQL(LPCTSTR lpszSQL);

As you can see, ExecuteSQL takes a single argument which is a null terminated string.
You're trying to pass two arguments.

PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes your code easier to to read and it also makes it easier to respond to your post.
it also makes it easier to respond to your post.

In particular, tags not only make your code nicely laid out and colo(u)red, they also add line numbers for all code fragments which are longer than one line. Something we can refer to in our response (I don't have time to line count!)

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello world\n"#

    return 0;
}


Here, I can say [you] need a ; rather a # at the end of line 6 without you having to work out which line that it.

Andy
Last edited on
Topic archived. No new replies allowed.