我正在尝试做一个应用程序而未添加一些有关汽车送货的详细信息。
我用C#和SQL编写了代码,但是当我将数据添加到textbox
,radiobutton
,labels
等中时,出现此错误:
System.Data.SqlClient.SqlException:'参数化查询'(@a int,@ b nvarchar(7),@ c int,@ d nvarchar(12),@ e nvarchar(10),@ f'参数'@f',未提供。'
但是我尝试通过调试来查看它们是否采用值并且所有值都小于@f
数据库中列的长度为50或100
if (materialRadioButton5.Checked)
{
choose = "Excelent";
}
else if (materialRadioButton8.Checked)
{
choose = "Foarte bună";
}
else if (materialRadioButton7.Checked)
{
choose = "Bună";
}
else if (materialRadioButton6.Checked)
{
choose = "Uzată";
}
if (materialRadioButton4.Checked)
{
chooser = "Mulţumit";
}
else if (materialRadioButton1.Checked)
{
chooser = "Nemulţumit";
}
SqlConnection con = new SqlConnection(stringcon);
SqlCommand cmd = new SqlCommand();
con.Open();
cmd.Connection = con;
cmd.Parameters.Clear();
cmd.CommandText = "insert into returncar(id_client,fullname_client,id_team,fullname_team,rendition,condition,team_mention,customers_plesed,exp_felt,client_mention) values(@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)";
cmd.Parameters.AddWithValue("@a", Convert.ToInt32(label65.Text));
cmd.Parameters.AddWithValue("@b", label67.Text);
cmd.Parameters.AddWithValue("@c", Convert.ToInt32(label66.Text));
cmd.Parameters.AddWithValue("@d", label68.Text);
cmd.Parameters.AddWithValue("@e", metroDateTime1.Text);
cmd.Parameters.AddWithValue("@f", choose);
cmd.Parameters.AddWithValue("@g", firstname_textbox.Text);
cmd.Parameters.AddWithValue("@h", chooser);
cmd.Parameters.AddWithValue("@i", role_dropbox.selectedValue);
cmd.Parameters.AddWithValue("@j", materialSingleLineTextField1.Text);
cmd.ExecuteNonQuery();
SqlCommand cmd2 = new SqlCommand();
cmd2.Connection = con;
cmd2.Parameters.Clear();
cmd2.CommandText = "update rentcar set inchiriat=0 where id=@id";
cmd2.Parameters.AddWithValue("@id", Form2.idddloan);
cmd2.ExecuteNonQuery();
con.Close();
panel2.Visible = false;
bunifuFlatButton7.Visible = false;
radiobutton4
和radiobutton1
的工作方式如何,而其他的无效?...
public string choose, chooser;
答案 0 :(得分:0)
如果该值为null,则不添加该参数,并且您将得到提到的异常。在这种情况下,请确保检查null并通过
choose ?? Value.DBNull