Question

Im trying to return the member id in this query below. If i run the query as just as a query i get 20 but when i exectute the code it returns a zero. What am i doing wrong here?

public int GetMemberID(string guid)
   {
       string strConectionString = ConfigurationManager.AppSettings["DataBaseConnection"];
       string StrSql = "SELECT MemberID FROM MEMBERS WHERE (Guid = @GuidID)";

       int memberId;
       using (var connection = new SqlConnection(strConectionString))
       using (var command = new SqlCommand(StrSql, connection))
       {
           command.Parameters.Add("@GuidID", SqlDbType.Int).Value = guid;
           memberId = (int)command.ExecuteScalar();
       }

       return memberId; 

   }
Was it helpful?

Solution

The guid variable is not an int.

command.Parameters.Add("@GuidID", SqlDbType.VarChar).Value = guid;

OTHER TIPS

Your paramter @GuidID is an Int type? Make sure it is right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top