this is a function for retrive two field in sql to combobox :
Code :
public void FillCmbKala()
{
cmbKala.Items.Clear();
objCon.Connecting();
string SQL = "SELECT [kID],[kName] FROM tblKala ORDER BY kName";
DataSet ds = new DataSet();
using (SqlConnection cn = new SqlConnection(objCon.StrCon))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(SQL, cn))
{
cn.Open();
try
{
adapter.Fill(ds);
}
catch (SqlException e)
{
MessageBox.Show("There was an error accessing your data of 'Kala'. DETAIL: " + e.ToString());
}
finally
{
cn.Close();
}
}
}
cmbKala.DataSource = ds.Tables[0];
cmbKala.DisplayMember = "kName";
cmbKala.ValueMember = "kID";
}
when i use the combobox return System.Data.DataRowView !
For Example :
string str= cmbKala.SelectedItem;
result is : str= System.Data.DataRowView
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…