怎么了?System.Data 中发生类型为"System.InvalidOperationException"的未处理异常.dll



private void button_Click_1(object sender, RoutedEventArgs e)
{
try 
{
if (isValid())
{
SqlCommand cmd = new SqlCommand("INSERT INTO DataEntry Values(@vehicleid,@vehiclename,@exteriorcolor,@interiorcolor,@model,@vin_number,@plate_number,@location,@option_codes,@dateofentry,@note),con");
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@vehicleid", txt_vehicleid.Text);
cmd.Parameters.AddWithValue("@vehiclename", txt_vehiclename.Text);
cmd.Parameters.AddWithValue("@exteriorcolor", txt_exteriorcolor.Text);
cmd.Parameters.AddWithValue("@interiorcolor", txt_interiorcolor.Text);
cmd.Parameters.AddWithValue("@model", txt_model.Text);
cmd.Parameters.AddWithValue("@vin_number", txt_vinnumber.Text);
cmd.Parameters.AddWithValue("@plate_number", txt_platenumber.Text);
cmd.Parameters.AddWithValue("@location", txt_location.Text);
cmd.Parameters.AddWithValue("@option_codes", txt_optioncode.Text);
cmd.Parameters.AddWithValue("@dateofentry", txt_dat.Text = string.Empty);
cmd.Parameters.AddWithValue("@note", txt_note.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
LoadGrid();
MessageBox.Show("Successfully registered", "Saved", MessageBoxButton.OK, MessageBoxImage.Information);
cleardata();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}

我不能100%确定这是特定的问题还是唯一的问题,但这是:

SqlCommand cmd = new SqlCommand("INSERT INTO DataEntry Values(@vehicleid,@vehiclename,@exteriorcolor,@interiorcolor,@model,@vin_number,@plate_number,@location,@option_codes,@dateofentry,@note),con");

应该是这样的:

SqlCommand cmd = new SqlCommand("INSERT INTO DataEntry Values(@vehicleid,@vehiclename,@exteriorcolor,@interiorcolor,@model,@vin_number,@plate_number,@location,@option_codes,@dateofentry,@note)", con);

请确保向右滚动以查看差异。

相关内容

最新更新