2017-04-19 66 views
-5
if (CheckBox1.Checked == false) 
{ 
    Label2.Text = "Enter Value !!"; 
    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);// error on this 
    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(); 
    con.Close(); 
    Label2.Visible = CheckBox1.Checked; 
    Label2.Text = " Your data is been saved in the database"; 
    Label2.ForeColor = System.Drawing.Color.ForestGreen; 
} 
+3

我想你錯過了提問的要點。 – Marco

+0

我的問題是非常直接的 – user31121992

+0

甚至沒有問號:D –

回答

0

嘗試的一個實例,的SelectedValue代替SelectedItem.Value

cmd.Parameters.Add("@CallType", ddlCalltype.SelectedValue); 
    cmd.Parameters.Add("@Format", ddlFormat.SelectedValue);// use SelectedValue 
    cmd.Parameters.Add("@Disposition", ddlDisp.SelectedValue); 
    cmd.Parameters.Add("@SubDisposition", ddlSubdisp.SelectedValue) 

;

+0

感謝兄弟:) – user31121992

+2

歡迎。不要使用'SelectedItem'而不檢查它是否爲空。 –

相關問題