Tuesday 5 March 2019

Inserting C# windows form data into Ms Access

                   Program in C# for creating  a connection with Ms access      and storing data in Access.
https://smileandcode.blogspot.com/2020/01/simple-python-program-in-jupyter.html
1. Create a Windows form like this.



2. Now go on new and create a new database in Ms Access.

3. After creating database create a new table in it.

Here we have create a database with name MCA4th and table with student name.

4. Now for creating a connection with database you need to add  using System.Data.OleDb; in form.

5.Now you need to create a connection object.
Code is this:

  public partial class Form1 : Form
    {private OleDbConnection connection= new OleDbConnection();
        public Form1()
        {
            InitializeComponent();
        }
6. Now write this code on button.

private void button1_Click(object sender, EventArgs e)
        {
            
            connection.ConnectionString=@"Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:\Documents and Settings\admin\My Documents\mca4th.accdb";
        connection.Open();
        OleDbCommand command= new OleDbCommand();
        command.Connection=connection;
        command.CommandText = "Insert into student (Name,Age,Class)values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "') ";
    command.ExecuteNonQuery();
    MessageBox.Show("Submitted");
    }

OUTPUT:-

3 comments:

DBMS NOTES UNIT 3

                                                              UNIT 3  ER (Entity Relationship) An entity-relationship model is known as an E...