I am working on a program on C# VS 2015. In my program, there is a big text display box that generates message when I click a certain button to indicate an action is being performed.
Anyway, I have a SQL script where it has queries for COUNT
for some tables. I can run that script through my program. However , since row count displays total number of rows for a table and can only be viewed inside SQL server. I was wondering is there a way to execute my script and also display the ROW COUNTS inside my program at the big text display box?
Here is a snippet of my code to run that SQL script:
/* open sql connection to execute SQL script: Row count script*/
try
{
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
FileInfo file = new FileInfo(DIRECTORY OF THE SCRIPT);
string script = file.OpenText().ReadToEnd();
Server server = new Server(new ServerConnection(con));
server.ConnectionContext.ExecuteNonQuery(script);
Display("ABCDG"); -- to display message on text display
con.Close();
}
}
catch (Exception ex)
{
textBox1.AppendText(string.Format("{0}", Environment.NewLine));
textBox1.AppendText(string.Format("{0} MainPage_Load() exception - {1}{2}", _strThisAppName, ex.Message, Environment.NewLine));
Display(ex.Message + ""); -- display message to textbox
textBox1.AppendText(string.Format("{0}", Environment.NewLine));
Debug.WriteLine(string.Format("{0} MainPage_Load() exception - {1}", _strThisAppName, ex.Message));
}
Here is a snapshot of my program:
https://i.stack.imgur.com/uKP99.png
See Question&Answers more detail:os