Click here to Skip to main content
15,904,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello


I am using VB 2008 and MS Access 2007 for a project.I have one combo box and five text box.I required a code that when a user select an item from the combo box ,the five text boxes fill automatically with the correspondence data from access .

Please guide by any experience person.

Thanks
Posted
Updated 31-May-14 22:33pm
v2
Comments
[no name] 1-Jun-14 4:29am    
Sorry, we don't write code to order here. You need to at least attempt to do this yourself or hire someone to do it for you.

 
Share this answer
 
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 Combobox
{
    public partial class Form1 : Form
    {
        string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
        OleDbCommand com;
        string str;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Text = "Select any id";
            comboBox1.Items.Add("Select any name");
            OleDbConnection con = new OleDbConnection(ConnectionString);
            con.Open();
            str = "select * from student";
            com = new OleDbCommand(str, con);
            OleDbDataReader reader = com.ExecuteReader();
            while (reader.Read())
            {
                comboBox1.Items.Add(reader["sid"].ToString());
            }
            reader.Close();
            con.Close(); 
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection(ConnectionString);
            con.Open();
            str = "select * from student where sid='" + comboBox1.Text + "'";
            com = new OleDbCommand(str, con);
            OleDbDataReader reader = com.ExecuteReader();
            while (reader.Read())
            {
                textBox1.Text = reader["sname"].ToString();
                textBox2.Text = reader["smarks"].ToString();
            }
            reader.Close();
            con.Close();
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900