Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to change name= 'gaurav' like that instead of below in my text visualizer plz help me!

SELECT id from employeemaster where name='System.Data.DataRowView'

if (comboBox1.SelectedIndex != -1)
              DataTable dt = new DataTable();
              SqlCommand tempcmd = new SqlCommand("SELECT id from employeemaster where name='" + comboBox1.SelectedValue.ToString() + "'", con);
              SqlDataAdapter adp = new SqlDataAdapter(tempcmd);
              if (dt.Rows.Count > 0)
                  label4.Text = dt.Rows[0]["id"].ToString();
                 // comboBox1.Text = dt.Rows[0]["specification"].ToString();

                  label4.Text = "";
Updated 27-Nov-13 21:24pm
JoCodes 28-Nov-13 2:25am    
Can you make the question bit clear?
Debopam Pal 28-Nov-13 2:52am    
Not clear...Write your question in simple way and in proper english. I really couldn't understand what you're trying to say after reading 5-6 minutes.
Karthik_Mahalingam 28-Nov-13 4:49am    
post the code where u r binding the data to the combobox..

int comboBoxID = comboBox1.SelectedIndex;
            string strId = this.comboBox1.Items[comboBoxID].ToString();

            MessageBox.Show("Select Text Is :" + strId);
Share this answer
Try this code..

private void Form1_Load(object sender, EventArgs e)

           DataTable dt = new DataTable();
           dt.Columns.Add("Name", typeof(string));
           dt.Columns.Add("ID", typeof(int));
           dt.Rows.Add("aaaa", 1);
           dt.Rows.Add("bbbb", 2);
           dt.Rows.Add("cccc", 3);
           dt.Rows.Add("ddd", 4);
           dt.Rows.Add("eeee", 5);

           comboBox1.DataSource = dt.DefaultView;
           comboBox1.ValueMember = "ID";
           comboBox1.DisplayMember = "Name";


       private void button1_Click(object sender, EventArgs e)
           string name = ((DataRowView)comboBox1.Items[comboBox1.SelectedIndex]).Row["Name"]+"";
           int id = (int) ((DataRowView)comboBox1.Items[comboBox1.SelectedIndex]).Row["ID"];

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