isValidMemberNum

|
protected bool isValidMemberNum(string memNum, int nOption)
	{
		bool isValidMemNum = false;
		int nRunDBLookup = 0;

		if (memNum.Length != 11)
		{
			isValidMemNum = false;
		}
		else
		{
			/*
			 * nOption is to define whether Medicare, Medicaid, Regular, or no preference
			 * 0 = No Preference
			 * 1 = Medicare
			*/
			if (nOption == 1)
			{
				if (memNum.Contains('A') || memNum.Contains('B') || memNum.Contains('C') || memNum.Contains('D'))
				{
					nRunDBLookup = 1;
				}
			}
			else if (nOption == 0)
			{
				nRunDBLookup = 1;
			}


			if (nRunDBLookup == 1)
			{
				try
				{
					string strSql = "SELECT * FROM AmisysUser WHERE MemberNo = '" + memNum + "'";
					SqlConnection sqlConn = new SqlConnection();
					sqlConn.ConnectionString = connString;
					sqlConn.Open();
					SqlCommand sqlCommand = new SqlCommand();
					sqlCommand.Connection = sqlConn;
					sqlCommand.CommandText = strSql;

					using (SqlDataReader dr = sqlCommand.ExecuteReader())
					{
						if (dr.HasRows)
						{
							isValidMemNum = true;
						}
						else
						{
							isValidMemNum = false;
						}
					}
				}
				catch (Exception isvaliderror)
				{
					Response.Write("ISVALID Error");
				}
			}
		}
		return isValidMemNum;
	}
Originally Posted on February 21, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.