Thursday 31 May 2012

Factorial of a number in C#



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, n, f;
            Console.WriteLine("enter the value of n");
            n = Convert.ToInt32(Console.ReadLine());
            f = n;
            for (i = n - 1; i >= 1; i--)
            {
                f = f * i;
            }
            Console.WriteLine("Factorial of given number is :" + f);
            Console.Read();
        }
    }
}

Wednesday 9 May 2012

How to Blink the Text from database in windows C# || How to Bind the Data from Database to a Label in Windows C#.Net

To implement this concept you need to follow the below steps :


Step1 :
First you need to design a table in Sql Database to retrieve the records from database.

Step2:
On the File menu, click New Project. Select Windows Forms Application as your project type.
Design the Form using controls from Toolbox.

Step3:
Now open the Form.cs page and write the following source code.

Form.cs Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        private const int _blinkFrequency = 250;
        private const int _maxNumberOfBlinks = 1000;
        private int _blinkCount = 0;
        SqlConnection con = new SqlConnection("Data Source=sridhar;Initial Catalog=Employee;User ID=sa;Password=123");

        public Form1()
        {
            InitializeComponent();
            Bind();
            timer1.Interval = _blinkFrequency; //optional: set in design code
            label1.Text = "";
            timer1.Start();
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            this.label1.Visible = !this.label1.Visible;
            _blinkCount++;
            if (_blinkCount == _maxNumberOfBlinks * 2)
            {
                timer1.Stop();
                label1.Visible = true;
            }
        }

        private void Bind()
        {
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("Select * from Emp_Details", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "Emp_Details");
            label1.DataBindings.Add("Text", ds, "Emp_Details.EmpName");

        }
    }
}


Step4:
Now build the Solution and Debug it for the output.

OutPut :


Tuesday 8 May 2012

How to search Records by keywords in DataGridView using Windows C#.Net

To implement this concept you need to follow the below steps :

Step1 :

First you need to design a table in MS Access 2007 Database to retrieve the records from database.


Step2:

On the File menu, click New Project. Select Windows Forms Application as your project type.

Design the Form using controls from Toolbox.


Step3:

Now open the Form.cs page and write the following source code.

Form.cs Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Visiting_Card
{
    public partial class Form2 : Form
    {
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\VisitingCard.accdb");
        public Form2()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            con.Open();
            OleDbCommand cmd1 = new OleDbCommand("VisitingCard_Search", con);
            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.Parameters.AddWithValue("@Names", txtKeyword.Text);
            OleDbDataAdapter da = new OleDbDataAdapter(cmd1);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            con.Close();
        }
    }
}


Step4:
Now build the Solution and Debug it for the output.

 OutPut :