Forums - C# Corner

Forum guidelines
kam

kam

  • 757
  • 5
  • 3.2k

call the main fuction

Dec 12 2012 7:36 PM
Hi;
I want to call the Main function of class Program, and pass a sql string to the Main fuction,
from the function of btn1Search_Click of the class Form1, when i click a button on the main form.

i am writing a project for database, and all the data put into the dataGridView. and i want the window displays another data when i click a button.

Could anyone tell me how to do that, please.

///////////////////////////////
  static class Program

  {
  public static string sql; 
  ///
  /// The main entry point for the application.
  ///

  [STAThread]
  static void Main(string[] args)
  {
  if (args.Length < 1)
  sql = "select buyerName, id, category, productName, price, date, referenceNo from elena ";
  else
  sql = args[0];

  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  Application.Run(new Form1(sql));

  }
  }
/////////////////////////////
  public partial class Form1 : Form
  {
  ........
  private void btn1Search_Click(object sender, EventArgs e)
  {

  }
  ...........

  }

Answers (8)

Cloud & IoT DevCon16

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.