好的,我正在为能够将新车添加到系统中的汽车经销商建立一个库存系统,现在我需要添加一个功能,如果经销商输入的汽车 REG 已经在数据库中,则会出现错误消息框。
我该怎么做?
继承人的代码:
MySqlCommand cmd = new MySqlCommand();
String carManufacture = textBoxCARManufac.Text.ToUpper();
String carModel = textBoxCARModel.Text.ToUpper();
String carColour = textBoxCarBodColo.Text.ToUpper();
int carMileage = int.Parse(textBoxCArMillea.Text);
int carYearReg = int.Parse(textBoxCARREGYear.Text);
String carReg;
String fuel = textBoxCARFuel.Text.ToUpper();
int carEng = int.Parse(textBoxCarEngSize.Text);
float carprice = float.Parse(textBoxCARPrice.Text);
float carTaxcost = float.Parse(textBoxCArTax.Text);
carReg = Regex.Replace(textBox1CARregplate.Text, " ", "").ToUpper();
try
{
cmd.CommandText = "INSERT INTO stockList (Manufacturer,CarModel,BodyColour,AquiredMileage,RegistartionYear,CarRegistration,FuelType,EngineSize,Price,CarTaxCost12Months) VALUES (@Manufacturer, @carModel, @carColour, @carMileage, @carYearReg, @carReg, @fuel, @carEng, @carPrice, @carTaxCost)";
cmd = SDS1.Prepare(cmd);
cmd.Parameters.AddWithValue("@Manufacturer", carManufacture);
cmd.Parameters.AddWithValue("@carModel" , carModel);
cmd.Parameters.AddWithValue("@carColour" , carColour);
cmd.Parameters.AddWithValue("@carMileage" , carMileage);
cmd.Parameters.AddWithValue("@carYearReg" , carYearReg);
cmd.Parameters.AddWithValue("@carReg" , carReg);
cmd.Parameters.AddWithValue("@fuel" , fuel);
cmd.Parameters.AddWithValue("@carEng" , carEng);
cmd.Parameters.AddWithValue("@carPrice" , carprice);
cmd.Parameters.AddWithValue("@carTaxCost", carTaxcost);
SDS1.Query(cmd);
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex);
}
}