I have a scenario where i have a DataSet bound to a combo box,
and i would like to read a row from the DataSet based on the item
selected in the Combo Box.
I have a dataset that has 1 table containing 2 fields say ID & Name.
This dataset is bound to a Combo Box with ID as a DisplayMember.
The Combo Box fills up perfectly with the ID field.
The problem i am facing is, when i select a ID from the Combo Box, i
would like to read the Name for that ID from the DataSet.
I did find a few samples but they would go through the loop to read
rows in a DataSet, but i could not find a sample where i can read a
row from a DataSet for a selected value.
Any help on this one will be much appreciated. Thanks.
Here's My Code
SqlConnection conn = new SqlConnection(" server="server_name"; database= "database_name"; integrated security= SSPI"); SqlCommand com1 = new SqlCommand(); com1 = new SqlCommand("SELECT EName FROM Emp_basic_det WHERE EID=@EID", conn); com1.Parameters.Add("@EID", SqlDbType.Int); com1.Parameters["@EID"].Value = EID_cmbox.SelectedItem; // Here the above line is not giving correct output.Its giving System.Data.Datarowview instead of ID. com1.Connection.Open(); com1.ExecuteNonQuery(); SqlDataAdapter adap1 = new SqlDataAdapter(com1); DataSet ds1 = new DataSet(); adap1.Fill(ds1); com1.Connection.Close();
//Now i Have to take Name based on ID Selection.
Can anyone kindly solve!!!!!!!