CodePudding user response:
Judge whether data exist, if not, perform loading, if present, return the data directly,CodePudding user response:
Reload? With what methodData 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 nullCodePudding 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