Table User:
Firstname:
Lastname:
Username:
Password:
Email:
Notification
Combobox--> show Firstname + lastname
Lable : Display username belong to selected item value from combo box.
Please share your idea.
Thnak you
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Apr 7, 2013, 3:03 AM
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 Fetch_multi_in_combobox
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Text = "Select";
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from emp";
com = new OleDbCommand(str, con);
oda = new OleDbDataAdapter(com);
ds = new DataSet();
oda.Fill(ds, "emp");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
comboBox1.Items.Add(ds.Tables[0].Rows[i]["Firstname"] + ds.Tables[0].Rows[i]["Lastname"].ToString());
}
con.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from emp where Firstname+Lastname='" + comboBox1.SelectedItem + "'";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
label1.Text = reader["Username"].ToString();
}
reader.Close();
con.Close();
}
}
}
Nazhand ZareeiPosted Apr 4, 2013, 12:04 PM
After selected value from combobox, display username on Textbox (Username) or Label
Kunal VaishyaPosted Apr 4, 2013, 6:47 AM
Select Eid,FirtsName+' '+LastName as FullName, EAddress,Esal
from Employee.
Combobox1.DataSource=ds.Tables[0];
Combobox1.DisplayMemberPath="FullName";
Combobox1.ValueMemberPath="Eid";
Vishal GilbilePosted Apr 4, 2013, 1:35 AM
What you can do is in your sql query you can merge the values of the two columns and provide an alias name to the new column. What I want to say is the following.
let's say i've one table named employee with fields as eid, efname,elname,eaddress,esal so inorder to display the firstname and lastname of employee on combobox together I can write my query like the following.
Select Eid,eFName+' '+eLName as Name, EAddress,Esal
from Employee.
Now while setting the combobox DataSource I can write like the following.
combobox1.DataSource=ds.Tables[0].DefaultView;
combobox1.DisplayMemberPath="Name";
Hope that solves your problem.
With Regards,
Vishal Gilbile.
Satyapriya NayakPosted Apr 4, 2013, 12:36 AM
{
comboBox1.Text = "Select";
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from emp";
com = new OleDbCommand(str, con);
oda = new OleDbDataAdapter(com);
ds = new DataSet();
oda.Fill(ds, "emp");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
comboBox1.Items.Add(ds.Tables[0].Rows[i]["Firstname"] + " " + ds.Tables[0].Rows[i]["Lastname"] + "");
}
}