Private voidForm1_Load (Objectsender, EventArgs e) { stringStrcon ="Server=localhost; User Id=sa; pwd=;D atabase=my";//Defining a database connection stringSqlConnection Sqlcon =NewSqlConnection (Strcon);//instantiating a database connection objectSqlDataAdapter sqlda_1 =NewSqlDataAdapter ("SELECT * from S", Sqlcon);//instantiating a database bridge objectDataSet myds =NewDataSet ();//instantiating a DataSet objectSqlda_1.fill (myDS,"Table_name_1");//populating a specified table in a data setmyDS. tables[0]. Columns.Add ("wage",typeof(int));//adding columns to Table_name_1myDS. tables[0]. Columns.Add (NewDataColumn ("Address",typeof(string))); DataRow Dr= myDS. tables[0]. NewRow ();//get data table, Row objectdr[0] ="S9"; dr[1] ="Lei";//adding data to a Row objectmyDS. tables[0]. Rows.Add (DR);//to add a row of data to a tableDatagridview1.datasource = myDS. tables[0];//Specify a data source for DataGridView1 table_name_1<=>0Sqlda_1.update (myds. tables[0]);//This sentence added there is a problem, only interface updates cannot be updated by the database }//Memory table DataTable Common Properties:columns-> Gets the collection of columns that belong to the table,rows-> gets the collection of rows belonging to the table
To add data to a database by applying a DataAdapter object--there is a problem