c# - Select data from table1 and copy it to table2 -


i real novice in c#.

i have seen many questions on here. but, on trying, not code.

i want columns of row retrieved , transfer table of same database.

so basically, retrieve data table1 , copy respective columns of table2.

i have tried code. , confused how call directly check string instead of defining each column in str1 string in " ".

 string check = "select * custdetails billid = @billid ";           sqlcommand cmd1 = new sqlcommand(check , conn);         cmd1.parameters.addwithvalue("@billid", billid);          dataset ds = new dataset();         sqldataadapter da = new sqldataadapter(cmd1);         da.fill(ds);        // string str1;         int count = ds.tables[0].rows.count;         if (count > 0)         {             string str1 = ds.tables[0].rows[0][""].tostring();         } 

i dont have idea c#. help.

you can using :

insert table2 (select *  table1 billid = @billid) 

the above gud when table1 & table2 had same structure. in case both table has different structure need change select * select [columns ,]...

one done copying data can carry on reading data application

string check = "select * custdetails billid = @billid ";  sqlcommand cmd1 = new sqlcommand(); // use command object copy table first.... cmd1.connection = conn; cmd1.commandtext = "insert table2 (select *  table1 billid = @billid)"; cmd1.executenonquery();  //then continue doing normal work cmd1.commandtext = check; cmd1.parameters.addwithvalue("@billid", billid);  dataset ds = new dataset(); sqldataadapter da = new sqldataadapter(cmd1); da.fill(ds); // string str1; int count = ds.tables[0].rows.count; if (count > 0) {     string str1 = ds.tables[0].rows[0][""].tostring(); } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -