1

I am trying to check if the user select (u.userId) is not in the column (urid) then only return true and run the other function. If the user selected data already exists, then return false. I get it with return void.. what happens? I'm still new in asp.net, hoping for some help. Thanks.

 public string URID { get; set; }

 public void urid_existence(User u)
 {
     DBHandler dbh = new DBHandler();
     dbh.OpenConnection();

     string sql = "select urid from FCS_COUGRP";

     if (u.UserID != u.URID)
     {
         userH.changeUrserGroup(u);
         return true;
     }
     else
     {
         return false;
     }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jan
  • 97
  • 1
  • 2
  • 11
  • 1) Does it compile? Change return type to bool. 2) Dispose your connection. 3) What's the point to have SQL command you don't execute? 4) Create a SqlCommand and execute a query. You may do everything in SQL using COUNT(*) and WHERE with ExecuteScalar() – Adriano Repetti Sep 01 '15 at 10:17
  • Note that the class `DBHandler` [seems fishy](http://stackoverflow.com/questions/9705637/executereader-requires-an-open-and-available-connection-the-connections-curren) to me, what does it do? Your sql query also is pointless because you don't use it and because you should use a `Where`-clause to filter in the database, f.e. if you want to check if a record with a given ID exists. – Tim Schmelter Sep 01 '15 at 10:31

1 Answers1

1

void means that the method does not return anything, but you want to return a bool. So this is the correct signature:

public bool urid_existence(User u)
{
   // ...
   if (u.UserID != u.URID)
   {
      userH.changeUrserGroup(u);
      return true;
   }
   else
   {
       return false;
   }
}
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939