How to show the datatable values in combobox?
-
hi all i want to show a column value from datatable.I tried as below . it doesnt shows the values. pls help.
SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataTable dtCust1 = new DataTable("CustomerDatTab"); adpt.Fill(dtCust1); dataGridView1.DataSource=dtCust1; //datagrid shows data. DataRow dr = new DataRow(); foreach (DataRow dr in dtCust1.Rows) comboBox1.Items.Add(dr.ToString()); //the below code also didnt works. i tried in the below way also //comboBox1.DisplayMember = "CompanyName"; //for (int i = 0; i < dtCust1.Rows.Count - 1; i++) //comboBox1.Items.Add(dtCust1); //comboBox1.DataSource = dtCust1.DefaultView;
thank usenthil
-
hi all i want to show a column value from datatable.I tried as below . it doesnt shows the values. pls help.
SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataTable dtCust1 = new DataTable("CustomerDatTab"); adpt.Fill(dtCust1); dataGridView1.DataSource=dtCust1; //datagrid shows data. DataRow dr = new DataRow(); foreach (DataRow dr in dtCust1.Rows) comboBox1.Items.Add(dr.ToString()); //the below code also didnt works. i tried in the below way also //comboBox1.DisplayMember = "CompanyName"; //for (int i = 0; i < dtCust1.Rows.Count - 1; i++) //comboBox1.Items.Add(dtCust1); //comboBox1.DataSource = dtCust1.DefaultView;
thank usenthil
kssknov wrote:
i want to show a column value from datatable.I tried as below . it doesnt shows the values.
Yes, you can get values from your DataTable. You could get them from either the DataGridView, or from the DataTable itself I'm just going to show you how to get them from the DataTable. Lets say you want to get all values from a specific column, here's how you would do it:
for (int rowIndex = 0; rowIndex < yourDataSet.yourDataTable.Rows.Count; rowIndex ++) { for (int columnIndex = 0; columnIndex < yourDataSet.yourDataTable.Columns.Count; columnIndex ++) { Console.WriteLine(string.format("Row {0}, Column {1} cell value is {2} !", rowIndex.ToString(), columnIndex.ToString(), yourDataSet.yourDataTable.Rows[rowIndex][columnIndex].ToString())); // for columnIndex you can use the column name if you'd like. } }
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")