Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me..

C#
public static bool CheckLogin(string username, string password, out int registerId, out int role, out string firstname)
  {
      bool isValid = false;

      registerId = default(int);
      role = default(int);
      firstname = string.Empty;

      using(MySqlConnection conn = new MySqlConnection(Constants.CONNECTION))
      {
          using(MySqlCommand cmd = new MySqlCommand(Constants.Procs.CHECK_LOGIN,conn))
          {
              cmd.CommandType = CommandType.StoredProcedure;

              cmd.Parameters.AddWithValue("_Email", MySqlDbType.VarChar).Value = username;
              cmd.Parameters.AddWithValue("_Password", MySqlDbType.VarChar).Value = password;

              conn.Open();

              using(MySqlDataReader reader = cmd.ExecuteReader())// here am getting error
              {
                  while(reader.Read())
                  {
                      isValid = true;

                      registerId = reader["RegisterID"] == System.DBNull.Value ? 0 : Convert.ToInt32(reader["RegisterID"]);
                      //role = reader["role"] == System.DBNull.Value ? 0 : Convert.ToInt32(reader["role"]);
                      //firstname = Convert.ToString(reader["Firstname"]);
                  }
              }
          }
      }
      return isValid;
  }
Posted
Comments
Pheonyx 22-Oct-13 7:28am    
Where are you getting the error? What have you tried?
NagarajDJ 22-Oct-13 7:31am    
using(MySqlDataReader reader = cmd.ExecuteReader())// here am getting error
am trying to send values to database and with matching values getting some information.
ZurdoDev 22-Oct-13 7:32am    
You need to reply to the comment instead of add a new comment to your own question.
ZurdoDev 22-Oct-13 7:31am    
The error should be pretty clear. What's the issue?
NagarajDJ 22-Oct-13 7:34am    
Ryan Dev, can you tell how can i solve this

Most likely the value of reader["RegisterID"] is not an integer. This error is thrown when you try to convert a value which is in incorrect format. For example - say you are trying to convert a string "abc" to integer.

Put a debugger and see what it's value is and you will be able to solve the issue.
 
Share this answer
 
Comments
NagarajDJ 22-Oct-13 7:35am    
No Mr. Ankur "RegisterID" in integer only
Ankur\m/ 22-Oct-13 7:38am    
I am sorry I didn't see the line of error. Regardless, put a debugger and see if you are passing values correctly to the stored procedure and there data types are correct (as required by the sp).
NagarajDJ 22-Oct-13 7:43am    
datatypes are correct to procedure, Previously also i have written this code but this time only am facing this problem
Thanks7872 22-Oct-13 7:50am    
You would have got a solution if you stopped the baseless comments and clearly point out the line where you got the error. Use Improve question widget and point out the line if you want quick resolution.
NagarajDJ 22-Oct-13 7:52am    
Rohan Leuva,

if you check my code, their i cleary mentioned in comments where i got error
By replacing

using (IDataReader reader = cmd.ExecuteReader())

with

using(MySqlDataReader reader = cmd.ExecuteReader())

i solved my error.
 
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