Home > Net >  WPF data reloading in c #
WPF data reloading in c #

Time:11-14

I use the same data source, but just want to refresh, make the DataGrid reload, but after I reload, appeared a duplicate records, is there any way to empty the DataGrid first

CodePudding user response:

Judge whether data exist, if not, perform loading, if present, return the data directly,

CodePudding user response:

Reload? With what method
Data binding you don't need to empty the DataGrid
Need is the data in the data source for line, estimation is the duplicate records in data source

CodePudding user response:

Private void PRODUCT_Click (object sender, RoutedEventArgs e)
{
String SQL="SELECT ProID, ProName, ProMarketPrice, ProPrice, ProAmount, ProSales FROM products";//SQL statement
SqlDataAdapter dataadapters=new SqlDataAdapter (SQL, conn);//define a dataadapters
Dataadapters. The Fill (dataSet, "commodity table");//fill data set
Enclosing DataGrid_messager. ItemsSource=dataSet. Tables [table "goods"] DefaultView;//fill data into the control
}

I in this button to add the event, click on the button, will show in the DataGrid data table, but repeated clicks, before the data is not going to disappear, but will appear to repeat data in this table, want to ask, is there any way to clear the previous data tables

CodePudding user response:

Use of what components? Can be ascribed value is null

CodePudding user response:

Using a DataGrid, is c # WPF, tried, can not be set to null,

CodePudding user response:

CodePudding user response:

I guess you DataSet is duplicate filling ,
Dataadapters. The Fill (dataSet, "commodity table");//fill data set //here the dataSet and possibly old data
You can create a dataSet and see if the problem exists,


If you do not set primary key, the Fill is cause duplicate data for many times, see Microsoft document
https://docs.microsoft.com/zh-cn/dotnet/api/system.data.common.dbdataadapter.fill

reference
using the following the Fill to refresh the content of the DataSet, must meet two conditions:

SQL statements should match the original used to fill the DataSet,

Key column information must exist, if the primary key information exists, then the DataTable can be repeated for all lines to coordinate, and only once, which appears in the corresponding DataSet in FillSchema can AddWithKey specified PrimaryKey DataTable attributes or will MissingSchemaAction attribute is set to to set the primary key information,

CodePudding user response:

My data tables are in the primary key, but it still repeated, per click run at a time, just load once

CodePudding user response:

Thank you, I solved the problem, I added to empty the dataset in this function is the first sentence,

CodePudding user response:

Refresh the controls
  •  Tags:  
  • C#
  • Related