Hi as per your query i have made a code for you in C# which will use the access database,
Now what happens in this code is that i am loading the employees id in a combobox on a form load and then the user has to select a particular id from the combobox and click a button. On button click user will get the name of an employee in a textbox
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database1.mdb;Persist Security Info=False");
con.Open();
string query = "Select name1 from mytable where id='"+comboBox1.Text+"'";
OleDbCommand cmd = new OleDbCommand(query,con);
OleDbDataReader dr = cmd.ExecuteReader();
if(dr.Read()==true)
{
textBox1.Text = dr[0].ToString();
}
else
{
MessageBox.Show("No such record");
}
con.Close();
con.Dispose();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database1.mdb;Persist Security Info=False");
con.Open();
string query = "select id from mytable";
OleDbCommand cmd = new OleDbCommand(query, con);
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read() == true)
{
comboBox1.Items.Add(dr[0].ToString());
}
con.Close();
con.Dispose();
}
}
}
Do rate my answer once you find it useful
Thanks & Regards
Radix :)