Home > Net > SQLdataAdapter changes inside the dataset data content for help
SQLdataAdapter changes inside the dataset data content for help
Time:10-21
Encounter problems when learning SQLdataAdapter, String constr=@ Server="WANGDEFU - PC \ WANG; User=sa; The PWD=1; The database=E_market ";//E_market is database SqlConnection mysqlcon=new SqlConnection (constr);//the new class
Mysqlcon. The Open ();//open the database TextBox1. Text="database is opened; String SQL="select * from myinfor";//myinfor data table SqlDataAdapter myda=new SqlDataAdapter (SQL, mysqlcon); The DataSet myds=new DataSet (); Myda. The Fill (myds, "Userinfo1");//I understand is to map the query results to Userinfo1 inside, and the name can casually up?
String updatesql="update Userinfo1 set ID=45 where ID=100";//operating memory Userinfo1 tables inside the ID=100 rows into ID=45 Myda. UpdateCommand=new SqlCommand (updatesql mysqlcon);
Myda. Update (myds, "Userinfo1");
The problem is to run the program without an error, but the data table and no update? My goal is 1, first of all, the database of myinfor data table is mapped to the memory in the dataset Userinfo1 table 2 for modified Userinfo1 table "update Userinfo1 set ID=45 where ID=100"; 3. The modified synchronous to the actual database tables myinfor, Also thank you please help solve specific how should do
CodePudding user response:
Read no problem,
Modify other SQL Mao Yong no,
For each row as datarow Userinfo1. In rows If the row (" ID ")=100 THEN row (" ID ")=45
NEXT Myda. Update (myds, "Userinfo1")
CodePudding user response:
1 - what do you want to modify the DATATABLE is what you get, write words made him into a SQL UPDATECOMMAD pointless,
2 - updatecommand is useful when you modify the datatabel, so datarow attributes into the edit? Or after the UPdate of what hi, UPdate the data in the use of logic, without modifying the datatable, this statement won't trigger,