Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Code:

C#
public string LoginHandler(string strEmail_Id, string strPassword,  out int strID, out string strName, out string strRole, out int Status_Parameter, out string Status_Msg)
 {
     DbCommand objlogin = null;

     try
     {
         objConn = dbkhorizon.CreateConnection();
         if (objConn.State == ConnectionState.Closed)
         {
             objConn.Open();
         }
         objlogin = objConn.CreateCommand();
         string strlgn = "usp_login_main";
         objlogin.CommandType = CommandType.StoredProcedure;
         objlogin = dbkhorizon.GetStoredProcCommand(strlgn);


         dbkhorizon.AddInParameter(objlogin, "@email_id", DbType.String, strEmail_Id.Trim());
         dbkhorizon.AddInParameter(objlogin, "@password", DbType.String, strPassword.Trim());

         dbkhorizon.AddOutParameter(objlogin, "@ID", DbType.Int32, 3000);
         dbkhorizon.AddOutParameter(objlogin, "@User_Name", DbType.String, 100);
         dbkhorizon.AddOutParameter(objlogin, "@role", DbType.String, 100);
         dbkhorizon.AddOutParameter(objlogin, "@errordesc", DbType.String, 200);

         DataSet ds = new DataSet();
         DataTable dt = new DataTable();
         ds = dbkhorizon.ExecuteDataSet(objlogin);
         dt = ds.Tables[0];

         if (dt.Rows.Count == 0)
         {
             Status_Parameter = 0;
             Status_Msg = "LOGIN FAILED";
         }
         else
         {
             Status_Parameter = 1;
             Status_Msg = "LOGIN SUCCESS";
         }

         strID = Convert.ToInt32(objlogin.Parameters["@ID"].Value);
         strName = (objlogin.Parameters["@User_Name"].Value).ToString().Trim();
         strRole = (objlogin.Parameters["@role"].Value).ToString().Trim();

     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (objConn.State == ConnectionState.Open)
         {
             objConn.Close();
             objConn.Dispose();
             dbkhorizon = null;
         }
     }

     return Status_Msg;
 }

getting error as object cannot be cast from DBNull to other types!(in the line strID)
I checked my Stored Procedure output also i got the integer value.
Posted
Updated 7-May-13 19:11pm
v2

1 solution

Hi Riyaz,

Are you sure you are getting some value from SP? Did you verify the specified column name is correct i.e., ID?

Please check verify again and let me know and provide the full exception details to understand it properly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900