' System.Reflection.TargetInvocationException'发生在System.Windows.ni.dll中

时间:2016-08-16 10:10:51

标签: c# .net wcf windows-phone-8

我正在开发WP 8.1应用程序,我正在使用WCF服务但是当我运行我的应用程序时它给了我以下例外: "未处理的类型' System.Reflection.TargetInvocationException'发生在System.Windows.ni.dll中。附加信息:调用目标抛出了异常"。 这是我的IService1.cs方法:

[OperationContract]
string Insert_ChallanDetails(Insert_Challan challan);

这是我的service.svc.cs实现:

public string Insert_ChallanDetails(Insert_Challan challan)
{
    string Message;
    SqlConnection conn = new SqlConnection(connection_string);
    conn.Open();
    SqlCommand cmd = new SqlCommand("INSERT INTO Voilation (Name,Voilation_place,Home_address,Licence_No,Place_issue,Reg_no,Offence1,Offence2,Offence3,Penalty1,Penalty2,Penalty3,Rs)VALUES (@Name,@Voilation_Place,@Address,@Licence_No,@Location,@Registration_No,@Offence_Code_1,@Offence_Code_2,@Offence_Code_3,@Penalty_1,@Penalty_2,@Penalty_3,@Total)", conn);
    cmd.Parameters.Add("@Name",System.Data.SqlDbType.Text).Value=challan.NAME;
    cmd.Parameters.Add("@Voilation_Place", System.Data.SqlDbType.Text).Value = challan.VIOLATION_PALCE;
    cmd.Parameters.Add("@Address", System.Data.SqlDbType.Text).Value = challan.ADDRESS;
    cmd.Parameters.Add("@Licence_No", System.Data.SqlDbType.Text).Value = challan.LICENCE_NO;
    cmd.Parameters.Add("@Location",System.Data.SqlDbType.Text).Value=challan.LOCATION;
    cmd.Parameters.Add("@Registration_No", System.Data.SqlDbType.Text).Value = challan.REGISTRATION_NO;
    cmd.Parameters.Add("@Offence_Code_1",System.Data.SqlDbType.Text).Value=challan.OFFENCE_CODE_1;
    cmd.Parameters.Add("@Offence_Code_2", System.Data.SqlDbType.Text).Value = challan.OFFENCE_CODE_2;
    cmd.Parameters.Add("@Offence_Code_3", System.Data.SqlDbType.Text).Value = challan.OFFENCE_CODE_3;
    cmd.Parameters.Add("@Penalty_1", System.Data.SqlDbType.Money).Value = challan.PENALTY_1;
    cmd.Parameters.Add("@Penalty_2", System.Data.SqlDbType.Money).Value = challan.PENALTY_2;
    cmd.Parameters.Add("@Penalty_3", System.Data.SqlDbType.Money).Value = challan.PENALTY_3;
    cmd.Parameters.Add("@Total", System.Data.SqlDbType.Money).Value = challan.TOTAL;
    int result = cmd.ExecuteNonQuery();
   if(result==1)
   {
       Message = challan.NAME + "Challan Inserted Sucessfully";
   }
   else
   {
       Message = challan.NAME + "Challan Could not be Inserted";
   }
    return Message;
}

这是我在wp8中的按钮点击事件:

private void submit_button_Click(object sender, RoutedEventArgs e)
{
    try
    {
        Insert_Challan challanInfo = new Insert_Challan();
        challanInfo.NAME = Name_Text.Text;
        challanInfo.LOCATION = Location_text.Text;
        challanInfo.ADDRESS = address_text.Text;
        challanInfo.LICENCE_NO = Licence_text.Text;
        challanInfo.VIOLATION_PALCE = IssuePlace_text.Text;
        challanInfo.REGISTRATION_NO = RegNo_text.Text;
        challanInfo.OFFENCE_CODE_1 = code1_text.Text;
        challanInfo.OFFENCE_CODE_2 = code2_text.Text;
        challanInfo.OFFENCE_CODE_3 = code3_text.Text;
        challanInfo.PENALTY_1 = decimal.Parse(Penalty_1.Text);
        challanInfo.PENALTY_2 = decimal.Parse(Penalty_2.Text);
        challanInfo.PENALTY_3 = decimal.Parse(Penalty_3.Text);
        challanInfo.TOTAL = decimal.Parse(total_text.Text);
        try
        {
            service.Insert_ChallanDetailsCompleted += new EventHandler<Insert_ChallanDetailsCompletedEventArgs>(service_Insert_ChallanDetailsCompleted);
            service.Insert_ChallanDetailsAsync(challanInfo);

        }
        catch(Exception ex)
        {
            MessageBox.Show(ex+"");
        }
        //service.Insert_ChallanDetailsCompleted += new EventHandler<Insert_ChallanDetailsCompletedEventArgs>(service_Insert_ChallanDetailsCompleted);
    }
    catch(Exception ex)
    {
        throw (ex);
    }
}

0 个答案:

没有答案