19 July 2016

Create Public/Global Variables in c#

Write this code in Program.cs as "Public class program" under namespace 'project name' by Constructors

public class Program
    {
        public OleDbConnection Cn;
        public OleDbCommand cmd;
        public OleDbDataAdapter DAdap;
        public OleDbDataReader rs;
        public Program()
        {
            Cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Application.StartupPath + "/Data.mdb");
            Cn.Open();
            cmd = new OleDbCommand();
            DAdap = new OleDbDataAdapter();
        }


Here program is a contructor. You can call anywhere in project by create program class.

Thank You! :)

No comments:

Post a Comment