Tuesday, 26 June 2012

Display records as First-Next-Previous-Last in a Textboxes and Show record in a Gridview?


Here i am first time Explain widow based programming that how to Display records as First-Next-Previous-Last in a Textboxes and Show record in a Gridview?




Here Code of window application....

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.Configuration;
using System.Data.SqlClient;
using System.IO;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataSet ds;
        SqlDataAdapter da;
        SqlConnection con;
        int i = 0;
       
        private void Form1_Load(object sender, EventArgs e)
        {
            con = new SqlConnection("Data Source=PANKAJ-PC;Initial Catalog=pankurani;Integrated Security=True");
            con.Open();
             da = new SqlDataAdapter("select * from emp1", 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...