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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql DataSet help

Status
Not open for further replies.

joecoolish

Programmer
Jan 26, 2005
8
0
0
US
k, so I want have a db that creates a record of who enters the site and at what time. I also want to do a check to see if they have ever been there before. The site is hosted on the local intranet, and it takes the users NT Login.

the obj that i get the NTID from is
IIdentity wi = WindowsIdentity.GetCurrent();
and I get it to a string with the
wi.Name.ToString();

I connect, and query the database with this:

this.Open(); //member function that opens the db conn
string dbtemp="", query1 = "SELECT "+column+" FROM "+table+" WHERE "+column+"=\'"+search+"\'";
[string column = "ntid", table = "userInfo", search = wi.Name.ToString();] // normally these are parameters inputed into the function, that's why there is []
SqlCommand cmd = new SqlCommand(query1, mySqlConn);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);

k, so I've just queried to see if their NTID is in the db already, and I have a DataSet with the info, so my question is, how do I compare the 2 (the info in the DS and the wi.Name.ToString();)? And how do i get the value of a single row with a DataSet? Is there an easier way?

Thanks!
Joel
 
Get a row from the dataset:
DataRow dr=ds.Tables.Rows[j];
where i<ds.Tables.Count and j<ds.Tables.Rows.Count;
So,the single row from the single table of the ds DataSet:
Code:
if (ds.Tables.Count> 0 and ds.Tables[0].Rows.Count>0)
{
    DataRow dr = ds.Tables[0].Rows[0];
    if (dr["ntid"].ToString()==wi.Name.ToString())
    {
        // they are equal
    }
}
[code]
Maybe you should apply ToLower(), Trim() etc:
[code]
if (dr["ntid"].ToString().ToLower()==wi.Name.ToString().ToLower())
{
   // they are equal
}
obislavu
 
thanks! I actually just figured out that the field for "ntid" is a "char" with a max of 35, so when I echoed out the length of the value I was getting from that feild was 35 characters long, no matter what, so I just created some code that passes the length of the logged on users name, and then trimmed the value returned string to that length, and saw if they were equal. Wow, that's confusing, but hey, it worked. . . thanks for the help! I didn't think of the ToLower thou, wow, that completely slipped my mind!

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top