Click here to Skip to main content
15,891,846 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!  All my friends!
Please help me, it’s my first project  for airport (student practice).  I’m learning coding C# My Data base connected  to  forms DataGridView and I see any changes real time (used SqlDependency).

Next step, how can I do for example when changes one column in Database (flight condition)  withdraw "flight_number, destination_airport" and paste this information (variable value) in template string "Dear passenger ''flight_number'' to ''destination_airport'' was canceled. (passenger display notifications). 
How can I do for C#, please give an example code. sorry my English, i hope you understand me. Thank you!


What I have tried:

//Load Data
       void LoadData()
       {
           DataTable dt = new DataTable();
           if (con.State == ConnectionState.Closed)
           {
               con.Open();
           }
           SqlCommand cmd = new SqlCommand("SELECT flight_number, destination_airport, flight_status, checkin_place, gate FROM DFP", con);
           cmd.Notification = null;

           SqlDependency de = new SqlDependency(cmd);
           de.OnChange += new OnChangeEventHandler(de_OnChange);

           dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection));
           dataGridView1.DataSource = dt;

       }
       public void de_OnChange(object sender, SqlNotificationEventArgs e)
       {
           SqlDependency de = sender as SqlDependency;
           de.OnChange -= de_OnChange;
           if (OnNewHome != null)
           {
               OnNewHome();
           }
       }
   }
Posted
Updated 20-Feb-17 15:29pm
Comments
[no name] 9-Feb-17 8:31am    
string.Format

string msg = string.Format("Dear passenger flight number {0} to destination_airport {1} was canceled. (passenger display notifications).",flight_number,destination_airport);
 
Share this answer
 
HI! Please write detailed code, how to insert in my code?
 
Share this answer
 
Comments
Graeme_Grant 20-Feb-17 21:32pm    
When replying, please use the reply or "Have a Question or Comment" button, not add a new solution to your question.
Graeme_Grant 20-Feb-17 21:34pm    
Additionally, this is called "Quick Answers" for a reason. We are not here to write your code for you but will point you in the right direction like the others have above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900