c# - Move rows from table to table -


i try move rows expired 1 table this:

mysqlconnection connect = new mysqlconnection(connectionstringmysql); mysqlcommand cmd = new mysqlcommand();  cmd.connection = connect; cmd.connection.open();  string commandline = @"insert history select clientid,userid,startdate,                        enddate,first,city,imgurl,phone,type,seen                         events startdate<now();";  cmd.commandtext = commandline;  cmd.executenonquery(); cmd.connection.close(); 

the table same (in each table have id column primary key, auto increment) , when run exception:

column count doesn't match value count @ row 1 

any idea why crash?

the reason why error because number of column on table doesn't match on number of values being inserted. usual when have auto-incrementing column on table inserting.

in order fix problem, need specify column name values inserted. example,

insert history (col1, col2,....) // << specify column names here select clientid, userid, startdate, enddate, first,         city, imgurl, phone, type, seen    events   startdate < now() 

i'm not pretty sure of column names of table history that's why need change column names valid names on table.

for instance have auto-incrementing column on table history , want leave query is, can pass null on select statement match total number of columns total number of values. example,

insert history  select null, clientid, userid, startdate, enddate, first,         city, imgurl, phone, type, seen    events   startdate < now() 

keep in mind in case won't specify column names, order of values matter.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -