我想用我的数据库列填充我的组合框,它们是 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 时转换失败