Skip to main content

to develop simple window application with database "customer.mdb" and "cust" table with customer name,address,town,country,postal 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 _2013
{
    public partial class Form1 : Form
    {
        OleDbCommand cmd;
        OleDbConnection con;
     
        string query = "";
        int f = 1;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\anuj vb 10\2013\Customer.mdb");
            label1.Text = "Customer name";
            label2.Text = "address";
            label3.Text = "town";
            label4.Text = "country";
            label5.Text = "postal code";
            button1.Text = "save";
            button2.Text = "update";
            button3.Text = "delete";
           

        }

        private void button1_Click(object sender, EventArgs e)
        {
            check();
            if (f == 0)
            {
                MessageBox.Show("insert data in all fields");
                return;

            }
            query="insert into cust values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"','"+textBox5.Text+"')";
            con.Open();
            cmd = new OleDbCommand(query, con);
            int r = cmd.ExecuteNonQuery();
            if (r > 0)
                MessageBox.Show("data entered");
            con.Close();

         }
        public void check()
        {

          f = 1;
            foreach (Control c in this.Controls)
            {
                if (c is TextBox)
                {
                    if (((TextBox)c).Text.Trim().Length <= 0)
                        f = 0;
                }
            }
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            check();
            if (f == 0)
            {
                MessageBox.Show("insert data in all fields");
                return;

            }
            query = "update  cust set address ='"  + textBox2.Text + "', town ='" + textBox3.Text + "', country ='" + textBox4.Text + "', postal_code ='" + textBox5.Text + "' where Customer_name ='"+textBox1.Text+"'";
            con.Open();
            cmd = new OleDbCommand(query, con);
            int r = cmd.ExecuteNonQuery();
            if (r > 0)
                MessageBox.Show("data updated");
            else
                MessageBox.Show("record not found");
            con.Close();

        }

        private void button3_Click(object sender, EventArgs e)
        {
           
            if (textBox1.Text.Trim().Length < 0)
            {
                MessageBox.Show("insert data in name field");
                return;

            }
            query = "delete from cust  where Customer_name ='" + textBox1.Text + "'";
            con.Open();
            cmd = new OleDbCommand(query, con);
            int r = cmd.ExecuteNonQuery();
            if (r > 0)
                MessageBox.Show("data deleted");
            else
                MessageBox.Show("record not found");
            con.Close();
        }
    }
}

Comments

Popular posts from this blog

PROGRAM TO PRINT COLOURS OF RAINBOW ACCORDING TO THE NO. INPUTTED BY THE USER

#include,stdio.h> #include<conio.h> void main() { int ch; printf("INPUT A NUMBER\n"); scanf("%d",&ch); switch(ch) { case 6: printf("Red"); break; case 5 : printf(" Orange"); break; case 4 : printf(" Yellow"); break; case 3 : printf(" Green"); break; case 2 : printf(" Blue"); break; case 1 : printf(" Indigo"); break; case 0 : printf(" Violet"); break; default : ("wrong input "); } } SIMPLE PROGRAMS FIND TYPE OF THE TRIANGLE TEMPERATURE CONVERSION COMMISSION OF A SALESMAN PRINT NUMBERS IN DESCENDING ORDER BIGGEST NUMBER AMONG THREE NUMBERS CALCULATE DIVISION A YEAR IS LEAP OR NOT A NUMBER IS ODD OR EVEN PRINT THE SQUARE ROOT ELSE PRINT N TO THE POWER 5 PRINT A NEW NUMBER BY ADDING 1 TO EACH DIGIT OF THE NUMBER PRINT THE NO. OF CURRENCY NOTES ACCORDING TO THE AMOUNT ENTERED DATA STRUCTURES ENTER DETAILS OF A STUDENT ENTER DETAILS OF A ST...

unix commands

 

Baby doge paws

Baby doge paws link 🎉 Join the BabyDoge PAWS Clicker adventure! Solve challenges, join daily events, and invite friends. Stay tuned for the token airdrop! 🐾 🌟 Earn 10k PAWS as a welcome bonus 🌟 Get 25k PAWS with Telegram Premium https://t.me/BabyDogePAWS_Bot?start=r_6394860582