Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql in visual c++ help!

Status
Not open for further replies.

jl3574

Programmer
Joined
Jun 5, 2003
Messages
76
Location
CA
if i create a C struct
typedef struct test
{
int age;
int number;
}
test s1;
s1.age=10;
s1.number=12;

i created a table in ms msq server with column age and number i want to put s1.age and s1.number in the table using executeSQL command.. like this

CDatabase* theDb = new CDatabase;
theDb->OpenEx("DSN=local");

i created a database object and connected to the local server

theDb->ExecuteSQL("insert into tablename(age,number) values(10,12) ");
using executeSQL i enter the sql command line,
instead of hard coding 10 and 12 how do i use variables in sql command line so i can refernce my struct to my database?
 
_TCHAR szSQL[64]={0}, szTable[32]={0};

_tcscpy(szTable,_T("Your_Table_Name"));

_stprintf(szSQL, _T("INSERT INTO %s(age,[number]) VALUES(%d,%d)"), szTable, s1.age, s1.number);

theDb->ExecuteSQL(szSQL);

Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top