I want to get Id on an selected Item in combBox. ComboBox has multiple items. I have tried like this.
public void getSaleDetail()
{
ClassConnection objConnection = new ClassConnection();
string getString = objConnection.conMethod();
SqlConnection con = new SqlConnection(getString);
try
{
SqlCommand command = new SqlCommand("SELECT S.sID, (CONVERT(VARCHAR,S.sDate,101)+' '+V.vName+' '+P.pType) AS SaleInfo FROM sale AS S INNER JOIN vendor AS V ON V.vID=S.vID INNER JOIN plant AS P ON P.pID=S.pID WHERE S.sPayment_Status='In Progress' ORDER BY S.sDate ASC", con);
con.Open();
SqlDataReader reader;
reader = command.ExecuteReader();
ArrayList SaleInfo = new ArrayList();
while (reader.Read())
{
SaleInfo.Add(reader[1].ToString());
}
cmbSale.Items.Clear();
cmbSale.Items.AddRange(SaleInfo.ToArray());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
con.Close();
}
}
in selectedIndexChanged event
string saleID = (string)cmbSale.SelectedValue.ToString();
SqlCommand cmd = new SqlCommand("SELECT sWeight FROM sale WHERE sID='"+saleID+"'", con);
con.Open();
float Weight = (float)cmd.ExecuteScalar();
txtWeight.Text = Weight.ToString();
please slove this issue.