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,



CodePudding user response:


refer to the second floor eaqpi response:
1 - you have to modify is you get the DATATABLE, 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,

What time would use the updatecommand this instruction? For the Internet to understand,

CodePudding user response:

reference weixin_37583883 reply: 3/f
Quote: refer to the second floor eaqpi 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,

What time would use the updatecommand this instruction? For the Internet to understand,



A total of four statements, addnew, update and delete, select
-- -- --

When used in datatable Addnew
Such as: dim datarow row=dt. Newrow
The row (" id ")=333
Dt. Rows. The add (row)

At that time, you use the ds. Update (dt), will use the addnew commmand,

With that statement is according to the row of the datatable state to choose, function is used for operating the datatable, can be generated automatically,

Can also write your own out strange requirements, such as delete rows in a datatable, and deletecommand may not delete statements, but update or new,

Can you make the sqldataAdapter automatic generation of the four statements, and your operations, just modify your data table,

Just remember, don't use the accept before update,











  •  Tags:  
  • C#
  • Related