c# - DataAdapter Update issue -
The following coding does not update my table but after updating the rows variable value is 1. I can not understand what is the reason behind it. help please.
SqlConnection connection1 = New SqlConnection (connectionString); Connection1.Open (); Var wktbl = new datatable (); Var CMD = New SQL Commands ("Select from Selection", Connection 1); Var da1 = new SqlDataAdapter (cmd); Var b = new SqlCommandBuilder (da1); Da1.Fill (wktbl); Wktbl.Rows [0] [2] = "5"; Da1.UpdateCommand = b.GetUpdateCommand (true); Int rows = da 1 Update (wktbl);
check out. This shows an example below with an update with Data Adapter.
The following examples demonstrate how to update the updates of modified rows to clearly call a DataAdapter UpdateCommand and update update method. Note that the parameter specified in the WHERE section of the UPDATE statement is set to use the original value of SourceColumn. This is important because the existing value can be modified and can not match the value in the data source. The basic value is the value that was used to populate the datatelle from the data source. {SqlConnection connection = New SqlConnection (connectionString)) {SqlDataAdapter DataApplication = New SqlDataAdapter ("Selection Category ID, By Category") By using Private Static Zero AdapterUpdate (String Connection String) {class} Categories ", connections); DataAdpater.UpdateCommand = New SqlCommand ("Update categories SET CategoryName = @CategoryName" + "where rangeID = @CategoryID", connection); DataAdpater.UpdateCommand.Parameters.Add ("@CategoryName", SqlDbType.NVarChar, 15, "CategoryName"); SqlParameter parameter = DataApeter.update command. Parameter. Add ("@CategoryDead", SQLDBtype.INT); Parameter. SourceColumn = "CategoryID"; Parameter. SourceVersion = DataRowVersion.Original; Datatelle categoryable = new datatable (); DataAdpater.Fill (categoryTable); Datourve rangeRo = categoryab.ro [0]; Category-line ["classname"] = "new beverage"; DataAdpater.Update (categoryTable); Console.print line ("rows after update."); Foreign currency (DataRow line in categoryTable.Rows) {{Console.WriteLine ("{0}: {1}", row [0], row [1]); }}}}
Comments
Post a Comment