| Razor 2005-12-12, 10:10 pm |
| something like the following should do it
using System;
using System.Data;
using System.Data.SqlClient;
namespace test
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class test
{
public bool IsValidUser(SqlConnection cndata , int intApplicationId,
string strUserId, string strPassword, ref string strMsg, ref bool
bValidUser)
{
try
{
// ****************************************
*******************************
//connect to the database using an existing connection
// ****************************************
*******************************
SqlCommand spCommand = new SqlCommand("SP_SEC_LOGIN", cndata);
spCommand.CommandType = CommandType.StoredProcedure;
// ****************************************
*******************************
//add the values for the specific parameters
// ****************************************
*******************************
SqlParameter param1 = new SqlParameter("@AppId", SqlDbType.Int);
param1.Direction = ParameterDirection.Input;
param1.Value = intApplicationId;
spCommand.Parameters.Add(param1);
SqlParameter param2 = new SqlParameter("@UserId",
SqlDbType.VarChar);
param2.Direction = ParameterDirection.Input;
param2.Value = strUserId;
spCommand.Parameters.Add(param2);
SqlParameter param3 = new SqlParameter("@Password",
SqlDbType.VarChar);
param3.Direction = ParameterDirection.Input;
param3.Value = strPassword;
spCommand.Parameters.Add(param3);
// ****************************************
*******************************
//Notice the type of results we expect from this paramerter
// ****************************************
*******************************
SqlParameter param4 = new SqlParameter("@ERROR_TYPE",
SqlDbType.Int);
param4.Direction = ParameterDirection.InputOutput;
param4.Value = 0;
spCommand.Parameters.Add(param4);
// ****************************************
*******************************
//instead of using .ExecuteNonQuery()
//you could just use
//WhateverDataset.Fill(dsPermissions)
//if you are expecting results from the Stored Procedure
// ****************************************
*******************************
spCommand.ExecuteNonQuery();
bValidUser =
System.Convert.ToInt32(spCommand.Parameters["@ERROR_TYPE"].Value) ==
-1;
if (!(bValidUser))
strMsg = "Stored Procedure failed";
return bValidUser;
}
catch (Exception ex)
{
strMsg = "IsValidUser - " + ex.Message + " AppId : " +
System.Convert.ToString(intApplicationId) + ", UserName: " + strUserId
+ ", Password: " + strPassword;
return false;
}
}
}
}
|