MySql alter table in c# error -


i trying perform

alter table 

command in app, when running, getting error

 have error in sql syntax; check manual corresponds mysql server version right syntax use near 'varchar(10) not null' @ line 1 

here code:

for (int k = 0; k < dlzkatab; k++) {  string query1 = "alter table reflextime add " + atributes[k] + " varchar(10) not null";  mysqlcommand cmd = new mysqlcommand(query1, conect);  cmd.executescalar();  } 

can please me?

edit:

here full code. in firs loop reading first row xls file , putting array atributes. can see, trying print out every loaded cell. worked (it printing correct values). after loop array printing nothing (empty messagebox).

  (int j = 2; j < colcount; j++)   {    string atr = xlrange.cells[1, j].text;    atributes[j]=atr;    messagebox.show(atributes[j]);   }   messagebox.show("súbor načítaný");   int dlzkatab = atributes.length;   messagebox.show(atributes[1]);  //empty messagebox   (int k = 0; k < dlzkatab; k++)  {  string query1 = "alter table reflextime add column " + atributes[k] + " varchar(10) not null";  mysqlcommand cmd = new mysqlcommand(query1, conect);  cmd.executescalar();   }  

i think trying add column table.

you missed column keyword in statement before column name being added.

"alter table reflextime add column " + atributes[k] + " varchar(10) not null" 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -