我有一个带有存储过程的表,它选择两列(用户名,密码)来返回一个值来验证用户在 android 登录页面上的登录。如何调用存储过程以返回一个值并将其与用户名和密码编辑文本框进行比较。
我的存储过程如下:
USE [Login_DB]
GO
StoredProcedure [dbo].[spLoginvalidate] Script Date: 03/13/2013
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[spLoginvalidate]
(
@User_ID varchar(50),
@Password varchar(20),
@Outres int OUTPUT
)
AS
BEGIN TRANSACTION
set @Outres= (SELECT count(*) FROM [dbo].Login
WHERE User_ID=@User_ID and Password=@Password
and CAST (Password as varbinary(20))=CAST (@Password AS varbinary(20)))
--WHERE CAST(Password AS varbinary(15)) = CAST(@Password AS varbinary(15))
if(@Outres=1)
begin
set @Outres=1
end
else
begin
set @outres=0
end
COMMIT TRANSACTION
这是我的代码:
class CheckLogin extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
Context context;
字符串电子邮件,密码;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
protected String doInBackground(String... args) {
// Building Parameters
// Send your email and password as the following parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Email", email));
params.add(new BasicNameValuePair("Password", password));
String url = "http://192.168.0.57:8000/Service1.svc/rest/Login";
JSONParser jParser = new JSONParser();
// This is the entire response like the JSON data you sent me
JSONObject json = jParser.makeHttpRequest(url, "GET", params, context);
// Check your log cat for JSON reponse
// CHECK LOGCAT IF YOU GET ANY RESPONSE FROM SERVER
Log.d("Results: ", json.toString());
try {
// Checking for SUCCESS TAG
JSONObject validateobject = json.getJSONObject("Details");
@SuppressWarnings("unused")
Boolean isloggedin = validateobject.getBoolean("Validat");
// THATS THE BOOLEAN THAT WILL INDICATE IF VALID LOGIN
// DO NOT MAKE CHANGES TO GUI ON THIS THREAD E.G. TOAST ETC
// USE THE ON POST EXECUTE BELOW ELSE THE APPLICATION WILL CRASH
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
}