Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie has issue with Generics

Status
Not open for further replies.

sirnose1

Programmer
Nov 1, 2005
133
0
16
US
I am new to generics and I am currently having an issue getting a method to hold the values in the list. Keeps going to null when it goes to return. I have added the data to the list from the dataset and I can access the values with ItemArray, however uit keeps returning null. I cant find the error. Thnaks in advance. Here is the code. It searches for someon in a profile db snd if it cant finf you there, it will search the Active Directory.

public List<string> user
{
get { return _user; }
set{ _user = value;}
}

public List<string> GetUser(string emailID)
{
//Method to get user from HEAT
string strSQL = "SELECT EmailID, FirstName, LastName, (ParentDepartment +'/' + Department) as Dept ";
strSQL += "FROM dbo.Profile WHERE EMailID = '" + emailID + "'";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["HEATMCConnectionString"].ConnectionString);

try
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "Profile");

// Declaration to get array of profile elements
List<string> user = new List<string>();

DataTable dt = ds.Tables["Profile"];
if (dt.Rows.Count < 1)
{
//Search the active directory if user not found in heat
GetUserByActiveDirectory(emailID);
}
else
{
//Gets the elements of the user. Email, first Name, last name and components
emailID = ds.Tables[0].Rows[0].ItemArray[0].ToString();
string firstName = ds.Tables[0].Rows[0].ItemArray[1].ToString();
string lastName = ds.Tables[0].Rows[0].ItemArray[2].ToString();
string component = ds.Tables[0].Rows[0].ItemArray[3].ToString();

//make list
user.Add(emailID);
user.Add(firstName);
user.Add(lastName);
user.Add(component);
}
return user;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top