Skip to main content

To develop simple window Application with database "School.mdb" and "student" table in the school.mdb database,student table with Roll no, Name and Address Field


//We will change name to s_name 

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 _2012
{
    public partial class Form1 : Form
    {
     //   OleDbCommand cmd;
        OleDbConnection con;
      //  OleDbDataReader dr;
        OleDbDataAdapter da;
        OleDbCommandBuilder builder;
        DataSet ds;
        string query = "";
        int max = 0,min=0;
        public Form1()
        {
            InitializeComponent();
            con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\anuj vb 10\2012\school.mdb");
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text = "roll no";
            label2.Text = "name";
            label3.Text = "address";
            button1.Text = "load";
            button2.Text = "previous";
            button3.Text = "next";
            button4.Text = "exit";

        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show("exitting from the application");
            Application.Exit();
        }
        private void fill()
        {
       

            textBox1.Text=ds.Tables[0].Rows[min]["roll_no"].ToString();
            textBox2.Text = ds.Tables[0].Rows[min]["s_name"].ToString();
            textBox3.Text = ds.Tables[0].Rows[min]["address"].ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            query = "select * from student";
                    da = new OleDbDataAdapter(query, con);
            builder =new OleDbCommandBuilder(da);
            ds=new DataSet();
            da.Fill(ds,"student");
           max= ds.Tables[0].Rows.Count;
           if (ds.Tables.Count > 0)
           {
               MessageBox.Show("the table is empty");
               return;
           }
            fill();
         
            con.Close();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            min -= 1;
            if (min == -1)
                min = max - 1;
            fill();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            min += 1;
                if(min==max)
                    min=0;
            fill();
        }
    }
}

Comments

Popular posts from this blog

unix commands