I am trying to finish my graduation project which is a desktop application for database transfer. The application was made by C# WPF. I want to introduce a feature in the application which is Quality Assurance, and it should be done as follows: When transfering a specific database, a message must be shown with the names of the tables in the database and the number of data rows in each table. I searched a lot for a solution to the problem but couldn't find anything specific. Can someone please write me the code for this feature in csharp?
here is xaml file:
<DataGrid Name="DataGridTable">
<DataGrid.Columns>
<DataGridTextColumn x:Name="DaGrTableName" Header="Table Name"/>
<DataGridTextColumn x:Name="DaGrRowsCount" Header="Row Count"/>
</DataGrid.Columns>
</DataGrid>
I tried with the following code, but it show just a message with number of tables and number of rows just from first table:
int rowsNbr = 0;
using MySqlDataReader mySqlDataReader = cmd.ExecuteReader();
while (mySqlDataReader.Read())
{
++rowsNbr;
}
int tableCount = 0;
string countTable = $"SELECT TABLE_NAME, SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{dbName}' GROUP BY TABLE_NAME;";
using MySqlConnection tableConn = new(connString);
using MySqlCommand tableComm = new(countTable);
tableComm.Connection = tableConn;
tableConn.Open();
using MySqlDataReader tableReader = tableComm.ExecuteReader();
while (tableReader.Read())
{
++tableCount;
}
transferedTextBlock.Text = $"{rowsNbr} Data Rows and {tableCount} Tables have been successfully transfered.";
The result should be displayed like this: