我在DataBase类中有一个驻留在App_Code中的方法,我用它来调用登录的存储过程,但是当我进行调用时,我没有收到任何错误,但我的登录将无法完成。
这是DataBase类:
func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)? = nil) {
// Construct a CXCallUpdate describing the incoming call, including the caller.
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: handle)
update.hasVideo = hasVideo
// Report the incoming call to the system
provider.reportNewIncomingCall(with: uuid, update: update) { error in
/*
Only add incoming call to the app's list of calls if the call was allowed (i.e. there was no error)
since calls may be "denied" for various legitimate reasons. See CXErrorCodeIncomingCallError.
*/
if error == nil {
print("calling")
}
}
}
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
let update = CXCallUpdate()
update.remoteHandle = action.handle
provider.reportOutgoingCall(with: action.uuid, startedConnectingAt: Date())
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "callStart"), object: self, userInfo: ["uuid":action.uuid])
action.fulfill(withDateStarted: Date())
}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "callStart"), object: self, userInfo: ["uuid":action.uuid])
// ACCEPT CALL ON SIP MANAGER
if let voiceCallManager = AppDelegate.voiceCallManager {
voiceCallManager.acceptCall()
}
action.fulfill(withDateConnected: Date())
}
这是我以前用来登录的代码:
public class DataBaseClass
{
SqlDataAdapter da;
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
public DataBaseClass()
{
}
public DataTable CallSP(string UserName, string Password)
{
con = new SqlConnection(@"Data Source=MyServer;Initial Catalog=MyDataBase;Integrated Security=True");
con.Open();
cmd = new SqlCommand("LoginUser", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 20).Value = "UserName";
cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 20).Value = "Password";
da = new SqlDataAdapter(cmd);
da.Fill(dt);
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
return dt;
}
这是我的存储过程:
DataBaseClass dbClass = new DataBaseClass();
dt = new DataTable();
dt = dbClass.CallSP("UserName", "Password");
if (dt.Rows.Count > 0)
{
boolReturnValue = true;
Session["UserId"] = dt.Rows[0]["Id"].ToString();
string updateLastLogin = "Update [User] SET LastLogin='" + System.DateTime.Now.ToString() + "' where Id='" + Session["UserId"].ToString() + "'";
dbClass.ConnectDataBaseToInsert(updateLastLogin);
}
return boolReturnValue;
}
任何人都可以复制我的代码并告诉我为什么我的登录电话无效。
答案 0 :(得分:1)
尝试在 CallSP 方法中执行以下更改:
cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 20).Value = UserName;
cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 20).Value = Password;
现在在你的代码中更多地关注我看到你的参数是在引号附近,所以你传递了文字字符串“UserName”和“Password”而不是值。
通过此更改,您将传递参数中的值。
对不起我的错误。
我希望它可以帮到你。