Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I am having a problem on implementing multi-column combo box (using windows combo box). I need to populate four fields from database into ComboBox (but not concatenated). I have the code given below. I getting error on every line. Please help me in this regard.



Thanks in advance.

C#
string selectString = "SELECT tCode,tName,tShName,tPrice " +
"FROM tTests " +
"WHERE dpCode =2";

DataTable dt = new DataTable();
con.Open();
SqlCommand sqlCmd = new SqlCommand(selectString, con);
sqlCmd.CommandTimeout = 0;
sqlCmd.CommandType = CommandType.Text;
sqlCmd.ExecuteNonQuery();
SqlDataAdapter adptr = new SqlDataAdapter(sqlCmd);
adptr.Fill(dt);


dt.Columns.Add("tCode", typeof(string));
dt.Columns.Add("tName", typeof(string));
dt.Columns.Add("tShName", typeof(string));
dt.Columns.Add("tPrice", typeof(string));


foreach (DataRow myDataRow in dt.Rows)
{
dt.Rows.Add("tCode = " + myDataRow["tCode"]);
dt.Rows.Add("tName = " + myDataRow["tName"]);
dt.Rows.Add("tShName = " + myDataRow["tShName"]);
dt.Rows.Add("tPrice = " + myDataRow["tPrice"]);
}

cboTests.DataSource = dt;
cboTests.DisplayMember = "tName";
cboTests.ValueMember = "tShName";
cboTests.SelectedIndex = -1;
cboTests.Text = "";
con.Close();
Posted
Comments
[no name] 20-Mar-13 15:50pm    
What exactly does "I getting error on every line" mean?

1 solution

See this: Multi-Column ComboBox[^] (CP article)
Another useful link: ListBox and ComboBox[^]
 
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