开发者

Adding columns with Variable names in SQL using C++, odbc

开发者 https://www.devze.com 2023-03-10 16:33 出处:网络
I am a beginner programmer and this is my first forum post, so please bear with me. I\'m using MS Visual C++ 2010 so send querys to MYSQL through an odbc connection.

I am a beginner programmer and this is my first forum post, so please bear with me.

I'm using MS Visual C++ 2010 so send querys to MYSQL through an odbc connection.

So far I have had no problem inputing values into my tables but i'm struggling to create columns.

for example;

if this is how you input values into sql tables:

SQLCHAR  Col1[10];

SQLINTEGER ch1;

rc = SQLPrepare(hStmt,(SQLC开发者_运维百科HAR*)"(hStmt,(SQLCHAR*)"INSERT INTO phonebook ( LastName) VALUES (?) ",SQL_NTS);

rc = SQLBindParameter(hStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, LENGTH, 0, Col1, 0, &ch1);

...// give ch1 and Col1 values

rc = SQLExecute(hStmt);

Then would I add columns the same way???

SQLCHAR  Col1[10];
SQLINTEGER ch1;

rc = SQLPrepare(hStmt,(SQLCHAR*)"ALTER TABLE phonebook ADD (? VARCHAR(45) NULL)",SQL_NTS);

rc = SQLBindParameter(hStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, LENGTH, 0, Col1, 0, &ch1);

...// give ch1 and Col1 values

rc = SQLExecute(hStmt);

Please help. If you could post some example code with your response so I can better understand.

Thank you so much in advance!

sarah

0

精彩评论

暂无评论...
验证码 换一张
取 消