必须声明标量变量“@Format”

时间:2017-04-18 11:56:31

标签: asp.net sql-server

<table>
    <thead>
        <tr>
            <th>Description</th>
            <th>Computer name</th>
            <th>Borrow date</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in tableData ">
            <td>{{row.data.AssetDescription}}</td>
            <td>{{row.data.ComputerName}}</td>
            <td>{{row.data.borrowDate}}</td>
        </tr>
    </tbody>
</table>
  

错误在executetenonquery上   错误发生在executiontenonquery

上      

错误发生在executiontenonquery

上      

错误发生在executiontenonquery

1 个答案:

答案 0 :(得分:0)

试试这个会对你有用:

if (CheckBox1.Checked == false)
{
    String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;
    SqlConnection con = new SqlConnection(strConnString);
    SqlCommand cmd = new SqlCommand("insert into CallCenter..Loy_DispMstr (CallType, SUBFormat, Disposition, SubDisposition) values (@CallType, @Format, @Disposition, @SubDisposition)", con);
    cmd.Parameters.Add("@CallType", ddlCalltype.SelectedItem.Value);
    cmd.Parameters.Add("@Format", ddlFormat.SelectedItem.Value);
    cmd.Parameters.Add("@Disposition", ddlDisp.SelectedItem.Value);
    cmd.Parameters.Add("@SubDisposition", ddlSubdisp.SelectedItem.Value);
    con.Open();
    int i = cmd.ExecuteNonQuery();
    con.Close();
    Label2.Text = " Your data is been saved in the database";
    Label2.ForeColor = System.Drawing.Color.ForestGreen;

}
else if (flag == 0 && CheckBox1.Checked == true)
{
    String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;
    SqlConnection con = new SqlConnection(strConnString);
    SqlCommand cmd = new SqlCommand("insert into CallCenter..Loy_DispMstr (CallType, SUBFormat,Disposition, SubDisposition) values (@CallType, @Format,@Disposition, @SubDisposition)", con);
    cmd.Parameters.Add("@CallType", ddlCalltype.Text);
    cmd.Parameters.Add("@Format", ddlFormat.Text);
    cmd.Parameters.Add("@Disposition", TextBox1.Text);
    cmd.Parameters.Add("@SubDisposition", TextBox2.Text);

    con.Open();
    int i = cmd.ExecuteNonQuery();//error on this
    con.Close();
}