Home > Net >  DataSet
DataSet

Time:11-10

Database has a column is on the column of
SqlDataAdapter adapter=new SqlDataAdapter ();//create an adapter
Adapter. The SelectCommand=new SqlCommand (" select * from table_1 ", connection).
SqlCommandBuilder builder=new SqlCommandBuilder (adapter);
Connection. The Open ();
DataRow row=testDataSet. Tables [r]. "table_1 NewRow ();
Row [1]="old xi";
The row [2]="male";
The row [3]=70;
"Table_1" testDataSet. Tables []. Rows. The Add (row);
Builder. GetUpdateCommand ();
Adapter. Update (testDataSet, "table_1");

An error row [0] cannot be null

SqlDataAdapter adapter=new SqlDataAdapter ();//create an adapter
Adapter. The SelectCommand=new SqlCommand (" select * from table_1 ", connection).
SqlCommandBuilder builder=new SqlCommandBuilder (adapter);
Connection. The Open ();
DataRow row=testDataSet. Tables [r]. "table_1 NewRow ();
Row [0]=testDataSet. Tables [r]. "table_1" Rows. Count + 1;
Row [1]="old xi";
The row [2]="male";
The row [3]=70;
"Table_1" testDataSet. Tables []. Rows. The Add (row);
Builder. GetUpdateCommand ();
Adapter. Update (testDataSet, "table_1");//an error here
System. InvalidOperationException: for SelectCommand does not return any key column information, does not support the UpdateCommand dynamic SQL generated,

CodePudding user response:

For the increase in a database table column set the primary key

CodePudding user response:

Set the primary key to row when [0] assignment in the adapter. After the Update (testDataSet, "table_1"); An error here
Don't give the row [0] assignment, an error: row [0] value cannot be null
  •  Tags:  
  • C#