Thursday, 12 April 2012

Windows programming in c#?

How to use next, privious and  search  record in grid view?

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataSet ds;
        SqlDataAdapter da;
        SqlConnection con;
        int i = 0;
        int j;
        private void Form1_Load(object sender, EventArgs e)
        {
           con = new SqlConnection("Data Source=PANKAJ-PC;Initial Catalog=employeewe;Integrated Security=True");
            con.Open();
             da = new SqlDataAdapter("select * from emp2", con);
            SqlCommandBuilder buil=new SqlCommandBuilder(da);
            ds = new DataSet();
            da.Fill(ds, "emp1");
            dataGridView1.DataSource = ds.Tables["emp1"];
           
        }
        private void b1_Click(object sender, EventArgs e)
        {
            if (ds.Tables[0].Rows.Count > 0) {
                i = 0;
                textBox1.Text = ds.Tables[0].Rows[i]["ID"].ToString();
                textBox2.Text = ds.Tables[0].Rows[i]["empname"].ToString();
                textBox3.Text = ds.Tables[0].Rows[i]["salary"].ToString(); }
        }
        private void b2_Click(object sender, EventArgs e)
        {
            i = ds.Tables[0].Rows.Count - 1;
            textBox1.Text = ds.Tables[0].Rows[i]["ID"].ToString();
            textBox2.Text = ds.Tables[0].Rows[i]["empname"].ToString();
            textBox3.Text = ds.Tables[0].Rows[i]["salary"].ToString();
        }
        private void b3_Click(object sender, EventArgs e)
        {
            if (i < ds.Tables[0].Rows.Count - 1) { i++;
                textBox1.Text = ds.Tables[0].Rows[i]["ID"].ToString();
                textBox2.Text = ds.Tables[0].Rows[i]["empname"].ToString();
                textBox3.Text = ds.Tables[0].Rows[i]["salary"].ToString();
            }
            else {
            }
        }
        private void b4_Click(object sender, EventArgs e)
        {
            if (i == ds.Tables[0].Rows.Count - 1 || i !=0)
            { 
                i--;
                textBox1.Text = ds.Tables[0].Rows[i]["ID"].ToString(); 
                textBox2.Text = ds.Tables[0].Rows[i]["empname"].ToString(); 
                textBox3.Text = ds.Tables[0].Rows[i]["salary"].ToString(); 
            }     
            else  
            {    
            } 
        }
        }
      
    }

No comments:

Post a Comment

What is ASP.NET? Components of ASP.NET

ASP.Net Definition -It is used for creating web-based applications.ASP.Net is a web development platform provided by Microsoft. ASP.NET i...