Programming for Everybody: connect with access database with password connect ms access
Showing posts with label connect with access database with password connect ms access. Show all posts
Showing posts with label connect with access database with password connect ms access. Show all posts

C# tutorial| connect with access database with password to retrieve data into textboxes -source code



using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.OleDb;


namespace connect_access_with_password

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            OleDbConnection oledconn = new OleDbConnection(@"Provider=Microsoft.Ace.Oledb.12.0;Data Source=F:\ddd.accdb;Jet Oledb:Database Password=123456");

            oledconn.Open();

            OleDbCommand olecomm = new OleDbCommand("Select firstname,lastname,points from table1 Where id = @id", oledconn);

            olecomm.Parameters.AddWithValue("id", textBox1.Text);

            OleDbDataReader oledreader;

            oledreader = olecomm.ExecuteReader();

            if (oledreader.Read())

            {

                textBox2.Text = oledreader["firstname"].ToString();

                textBox3.Text = oledreader["lastname"].ToString();

                textBox4.Text = oledreader["points"].ToString();

            }

            else

            {

                textBox2.Text = "";

                textBox3.Text = "";

                textBox4.Text = "";

                MessageBox.Show("No data found");

                


            }

            oledconn.Close();

        }

    }