Link to home
Start Free TrialLog in
Avatar of fwsteal
fwsteal

asked on

sql data set question with asp.net 2.0

I need to determine if user row exists and determine if cell phone number exists.
1. if cell number = 0 then false
2. if row does not exist then false

I know how to check if the row exists, but how do I check the value of a column?

protected bool HasMobileNumber(string strUserID)
 {
  //query table to determine presense of user cellphone number per userid
  String strConnection;
  strConnection = ConfigurationManager.ConnectionStrings["MYConnectionString"].ToString();
  SqlConnection objConnection = new SqlConnection(strConnection);
  string strSQL = "";
  DataSet objDataSet = new DataSet();
  strSQL = "Select userid, cellnumber, CASE WHEN ISNULL(cellnumber, '') != '' THEN 1 ELSE 0 END hascellnumber from usracct where user ='" + strUserID + "'";
  SqlDataAdapter objAdapter = new SqlDataAdapter(strSQL, objConnection);
  objAdapter.Fill(objDataSet, "dtUser_Logins");
//if hascellnumber in ds is 0 or (objDataSet.Tables["dtUser_Logins"].Rows.Count == 0)
//{
//return false;
//}
//else
//{
//return true;
//}
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Try:

    strSQL = "Select userid, cellnumber, CASE WHEN ISNULL(cellnumber, '') != '' THEN 1 ELSE 0 END hascellnumber from usracct where user ='" + strUserID + "' AND cellnumber != '0'";
Avatar of fwsteal
fwsteal

ASKER

wouldn't the cellnumber need to be ''

this way a row won't be returned?
Do you simply want to stop it returning any records with no cellnumber, or retireve them anyway and check afterwards ?
Avatar of fwsteal

ASKER

I guess, what I'm trying to do is not return a row if both conditions are false so this way I can just check if a row exists
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial