23 July 2016

how to get checkbox value in c#

p1.cmd = new OleDbCommand("insert into pass(name,pass,type1,add,edit,dele) values ('" + C1.Text.Trim() + "','" + textBox1.Text + "','" + C2.Text + "'," + (Ck1.Checked ? 1 : 0) + "," + (Ck2.Checked ? 1 : 0) + "," + (Ck3.Checked ? 1 : 0) + ")", p1.Cn);

here we get ck1.checked?1:0 = 1 while checked;
ck1.checked?1:0 = 0 while Unchecked;

Thank you !

Create Text file (or any basic format files) in C#

using System.IO;

            StreamWriter File = new StreamWriter("Bar.txt");
            File.Write("<html>");
            File.Write("<title>Test File</title>");
            File.Write("<head></head>");
            File.Write("<body bgcolor=blue>Hai This is Test Body</body></html>");
            File.Close();
            System.Diagnostics.Process.Start("Bar.txt");


Suggest Blog for daily News in Tamil: tamizhnewz.blogspot.in

Print File to Printer Different ways C#

Easy way to print file:

            PrintDocument pd = new PrintDocument();
            pd.PrinterSettings.PrinterName = "Hp Printer";
            pd.DocumentName = "Bar.txt";
            pd.Print();
            MessageBox.Show("Printer: Hp Printer" + " " + "\nFile: Bar.txt");

Another way to Print File:

         private void button1_Click(object sender, EventArgs e)
        {
            System.IO.StreamReader filetoprint;
              filetoprint = new System.IO.StreamReader(@"D:\\m.txt");
              printDocument1.Print();
              filetoprint.Close();
        }

Another way to Print File:

        var pi=new ProcessStartInfo("C:\file.docx");
        pi.UseShellExecute = true;
        pi.Verb = "print";
        var process =  System.Diagnostics.Process.Start(pi);


Suggest Blog for daily News in Tamil: tamizhnewz.blogspot.in 

Array in C#

Array
------
int[] myarray = { 100,200,300,400,500 };
string[] myarray = { "s1","s2","s3","s4","s5" };

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! :)

17 July 2016

Download and Install Visual Studio 20XX (C# Development Tool)

Goto this Site and download Visual Studio https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx

After download completed click complete install. It will automatically connect to internet and installed simultaneously. It may takes 3-4 hrs depends on internet speed. After installed you can see the message "Successfully installed" with option close. Click close then that's all. Thank You.