コンボボックスに、int と主キーであるデータベース列を入力したいと考えています。
private void cmbxIDno_SelectedIndexChanged(object sender, EventArgs e)
{
ResetTextBoxes();
SqlCommand SelectedID = new SqlCommand();
SelectedID.Connection = clsINIReader.nConn;
SelectedID.CommandText = "SELECT * FROM tools WHERE ID= '" + cmbxIDno.SelectedItem.ToString()+ "' ";
SqlDataReader drID = SelectedID.ExecuteReader();
while (drID.Read()) //Conversion failed when converting the varchar value 'Select ID No...' to data type int.
{
txtPN.Text = drID["PartNumber"].ToString();
txtNomenclature.Text = drID["Nomenclature"].ToString();
txtSerial.Text = drID["SerialNo"].ToString();
txtShelfNo.Text = drID["ShelfNumber"].ToString();
txtTSnumber.Text = drID["TSnumber"].ToString();
txtBinNumber.Text = drID["BinNumber"].ToString();
txtRentalPrize.Text = drID["RentalPrize"].ToString();
txtCurrency.Text = drID["Currency"].ToString();
txtQuantity.Text = drID["Quantity"].ToString();
txtCalibrDateInfo.Text = drID["CalibrationDate"].ToString().Replace("00:00:00", "");
txtCalibrationPeriod.Text = drID["CalibrationPeriod"].ToString();
txtCertfNumber.Text = drID["CertificateNo"].ToString();
textBox11.Text = drID["CertificationPath"].ToString();
txtIDno.Text = drID["ID"].ToString();
}
drID.Close();
}
しかし、私はこのエラーが発生します:
varchar 値 'Select ID No...' をデータ型 int に変換するときに変換に失敗しました