[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

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;
//}
0
fwsteal
Asked:
fwsteal
  • 3
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
Try:

    strSQL = "Select userid, cellnumber, CASE WHEN ISNULL(cellnumber, '') != '' THEN 1 ELSE 0 END hascellnumber from usracct where user ='" + strUserID + "' AND cellnumber != '0'";
0
 
fwstealAuthor Commented:
wouldn't the cellnumber need to be ''

this way a row won't be returned?
0
 
Carl TawnSystems and Integration DeveloperCommented:
Do you simply want to stop it returning any records with no cellnumber, or retireve them anyway and check afterwards ?
0
 
fwstealAuthor Commented:
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
0
 
Carl TawnSystems and Integration DeveloperCommented:
If you just use:
   
    strSQL = "SELECT userid, cellnumber FROM usracct WHERE user='" + strUserID + "' AND cellnumber IS NOT NULL"

Then you will not get any rows if the row doesn't exist, or if the cellnumber is not filled in. Then the test for your "if" simply becomes:

    if (objDataSet.Tables["dtUser_Logins"].Rows.Count == 0)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now