PDA

View Full Version : how to create a sql table {a int ,b int}, a &b are coming from user's input?



haopeng
25th December 2013, 10:12
sorry for my poor english.
i just want to get data from excel file(.xls) ,and use it to create a table like this: CREATE TABLE TEST( a INTEGER, b INTEGER); BUT a & b should come from excel. just like :

query = QSqlQuery(db);
query.prepare("INSERT INTO users(userName, passWord)"
"VALUES(?, ?)");
query.addBindValue(user);
query.addBindValue(pwd);
query.exec();

up there ,it is INSERT TO, BUT i want "CREATE", that is it!
how to do this ?
thanks in advance !thank you all!

haopeng
25th December 2013, 14:25
is there anybody that can help me ? using QString can solve this, just like "a"+s; but i think maybe we can use "prepare ".But how to use that? help,help ,help !

ChrisW67
25th December 2013, 20:51
If you want to create atable then execute a CREATE TABLE SQL statement then insert the rows one-at-a-time in a loop. You have the INSERT so you just need the add the loop.

haopeng
26th December 2013, 01:55
If you want to create atable then execute a CREATE TABLE SQL statement then insert the rows one-at-a-time in a loop. You have the INSERT so you just need the add the loop.
thank YOU very much, and sorry for my poor english . But what you said is not what i want ,i want CREATE TABLE(a string, b string) ,but the "a" and "b" come from user's input ,if i get 'username" and "password " from user,i have to do this: CREATE TABLE(username string , password string) , now can you understand ?thank you again!