23 July 2016

Crystal Report in C#

1) Add Reference as following



2) Add Axcrviewer9Lib view in form from Toolbox and rename control to CRV


3) Then copy this to your code section

 private void print_Load(object sender, EventArgs e)
        {
            CRAXDRT.Application crep = new CRAXDRT.Application();
            CRAXDRT.Report frep = new CRAXDRT.Report();
            this.Text = "Test Print";
            frep = crep.OpenReport("D:/Sofwares/Adagu/loan_rep.rpt", 1);
            p1.cmd = new OleDbCommand("select *,'Loan Report' as rname from loan", p1.Cn);
            p1.rs = p1.cmd.ExecuteReader();
            p1.rs.Read();
            frep.Database.SetDataSource(p1.rs);
            CRV.ViewReport();
            MessageBox.Show("Printed Successful");
        }


For more Details Mail to murugankarthik008@gmail.com

MsAccess Database Connection with C#

using System.Data.OleDb;

        Cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Data.mdb");
        Cn.Open();

How to save datagridview to access database c#

for(int i = 0; i < DGV.Rows.Count - 1; i++)
                {
                    p1.cmd = new OleDbCommand("insert into pmaster(name,sname,type,gro,code,odate) values ('" + C2.Text.Trim() + "','" + DGV[1,i]+"','"+C3.Text+"','"+C1.Text.Trim()+"','"+textBox1.Text.Trim()+"','"+DateTime.Now.Date+"')",p1.Cn);
                    p1.cmd.ExecuteNonQuery();
                }

How to save datagridview to access database c#

for(int i = 0; i < DGV.Rows.Count - 1; i++)
                {
                    p1.cmd = new OleDbCommand("insert into pmaster(name,sname,type,gro,code,odate) values ('" + C2.Text.Trim() + "','" + DGV[1,i]+"','"+C3.Text+"','"+C1.Text.Trim()+"','"+textBox1.Text.Trim()+"','"+DateTime.Now.Date+"')",p1.Cn);
                    p1.cmd.ExecuteNonQuery();
                }

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.