C# Angular JS应用程序因多个Post请求而失败
我正在使用来自AngularJs应用程序的WCF服务。我正在向该服务发布多个请求。通过此请求,我正在检查用户信息 这是引发错误的服务:C# Angular JS应用程序因多个Post请求而失败,c#,sql,wcf,C#,Sql,Wcf,我正在使用来自AngularJs应用程序的WCF服务。我正在向该服务发布多个请求。通过此请求,我正在检查用户信息 这是引发错误的服务: public bool cheekCreditScore(Credit_Crad credit) { int i = 600; int j = 700; SqlConnection cn = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlComman
public bool cheekCreditScore(Credit_Crad credit)
{
int i = 600;
int j = 700;
SqlConnection cn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT Credit_Score FROM Credit_Score WHERE Account_Number = '" + credit.account_number + "'", cn);
cn.Open();
cmd.Parameters.AddWithValue("Account_Number", credit.account_number);
var value = cmd.ExecuteScalar();
var da = new SqlDataAdapter(cmd);
DataTable tbl = new DataTable();
da.Fill(tbl);
if (tbl.Rows.Count == 0)
{
//message = ("Account is not exist Under this Name");
return true;
}
else if ((Convert.ToDouble(i) < Convert.ToDouble(value)) && (Convert.ToDouble(value) <= Convert.ToDouble(j)))
{
// message = "Application Successful We can offer you " + Value1 + "Pound";
return true;
}
else
{
// message = "Your application is unsuccessfull ";
return false;
}
//return false;
}
以下是我遇到的错误:
这是AngularJS Web应用程序中的脚本代码,这是我向Wcf Rest服务发布的多请求
var app = angular.module("WebClientModule", [])
.controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {
$scope.OperType = 1;
//1 Mean New Entry
//To Clear all input controls.
function ClearModels() {
$scope.OperType = 1;
$scope.Tittle = "";
$scope.First_Name = "";
$scope.Last_Name = "";
$scope.Gender = "";
$scope.DOB = "";
$scope.Mobile = "";
$scope.House_No = "";
$scope.Streent_Name = "";
$scope.Country = "";
$scope.Post_Code = "";
$scope.Occupation = "";
$scope.Account_Number = "";
}
$scope.CeditCardApplication = function () {
var ApplicationDeatils = {
Tittle: $scope.Tittle,
First_Name: $scope.First_Name,
Last_Name: $scope.Last_Name,
Gender: $scope.Gender,
DOB: $scope.DOB,
Mobile: $scope.Mobile,
House_No: $scope.House_No,
Streent_Name: $scope.Streent_Name,
Country: $scope.Country,
Post_Code: $scope.Post_Code,
Occupation: $scope.Occupation,
Account_Number: $scope.Account_Number
};
myService.ApplicationDeatilsCheck(ApplicationDeatils).then(function (pl) {
console.log(pl.data)
if (pl.data) {
//$scope.Account_Number = pl.data.Account_Number;
$scope.msg = "User information is correct !";
};
});
myService.ApplicationCreditScoreCheck(ApplicationDeatils).then(function (p2) {
console.log(p2.data)
if (p2.data) {
//$scope.Account_Number = p2.data.Account_Number;
$scope.msg = "We can offer you £6000";
} else {
$scope.msg = "Application failed !";
console.log("Some error Occured" + err);
}
}, function (err) {
$scope.msg = "Application failed!";
console.log("Some error Occured" + err);
});
} // <-- missing }
}]);
app.service("myService", function ($http) {
this.ApplicationDeatilsCheck = function (ApplicationDeatils) {
return $http.post("http://localhost:52098/HalifaxIISService.svc/CreateCurrentAccountCheck", JSON.stringify(ApplicationDeatils));
}
this.ApplicationCreditScoreCheck = function (ApplicationDeatils) {
return $http.post("http://localhost:52098/HalifaxIISService.svc/cheekCreditScore", JSON.stringify(ApplicationDeatils));
}
});
使用参数的全部目的是避免字符串连接并防止SQL注入。您的代码正在传递参数并连接:
SqlCommand cmd = new SqlCommand("SELECT Credit_Score FROM Credit_Score WHERE Account_Number = '" + credit.account_number + "'", cn);
cn.Open();
cmd.Parameters.AddWithValue("Account_Number", credit.account_number);
这显然是错误的,因为您正在传递一个查询甚至不知道的参数
只需将代码更改为:
SqlCommand cmd = new SqlCommand("SELECT Credit_Score FROM Credit_Score WHERE Account_Number = @Account_Number", cn);
cn.Open();
cmd.Parameters.AddWithValue("Account_Number", credit.account_number);
如果您有一条异常消息确切地告诉您问题出在服务上运行的SQL中,那么是什么特别让您认为您的客户机或第二个查询与此有关?这个问题中的大部分代码完全不相关,应该删除。请阅读如何创建@Mohammad,该@Mohammad只能在credit.account_number为null时使用,在这种情况下,您需要使用DbNull而不是headyes。它是空的。但我不知道是ado.net还是angular的问题js@Mohammad这可能是一个大小写问题,属性名在c中为camelCase,在Angular中为PascalCase,与正常情况相反。你有没有检查angular实际上在发送变量中的任何东西?使用chrome检查请求数据