code error

  • Thread starter Thread starter Hrcko
  • Start date Start date
H

Hrcko

what is wrong with this code ?


listUsers.DisplayMember = "UserName";

string UserIDSelect = "UserID not in "+ "(Select UserID "+

"From Users where Users.UserID ='" +
nUserID + "'" + ")";


DataRow[] Urows = db.dataSetAccounts.Users.Select(UserIDSelect);

foreach ( DataSetAccounts.UsersRow row in Urows )

{

DataSetAccounts.UsersRow users =

db.dataSetAccounts.Users.FindByUserID ( row.UserID );

if ( users != null )

{

listUsers.Items.Add( users );

}

}



Hrcko
 
Opps what are u trying to do??
string UserIDSelect = "UserID not in "+ "(Select UserID "+

"From Users where Users.UserID ='"
+ nUserID + "'" + ")";

Simply use
db.dataSetAccounts.Users.DefaultView=String.Format("UserID <>'{0}'
",nUserID);

And what is this ????
DataRow[] Urows = db.dataSetAccounts.Users.Select(UserIDSelect);

foreach ( DataSetAccounts.UsersRow row in Urows )
{

DataSetAccounts.UsersRow users =

db.dataSetAccounts.Users.FindByUserID ( row.UserID );

if ( users != null )

{

listUsers.Items.Add( users );

}

Select method iterates whole datatable once and then in the loop foreach row
you call FindByUserID which iterates whole table again and again. (n*n) What
about algorithm complexity ?

Clear whole code and simply iterate datatable one time

foreach ( DataSetAccounts.UsersRow row in Urows )
{
if (row.UserID==nUserID) continue;
listUser.Items.Add(row);
}

I think it is quite simple and faster than yours.....

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

Hrcko said:
what is wrong with this code ?


listUsers.DisplayMember = "UserName";

string UserIDSelect = "UserID not in "+ "(Select UserID "+

"From Users where Users.UserID ='"
+ nUserID + "'" + ")";


DataRow[] Urows = db.dataSetAccounts.Users.Select(UserIDSelect);

foreach ( DataSetAccounts.UsersRow row in Urows )

{

DataSetAccounts.UsersRow users =

db.dataSetAccounts.Users.FindByUserID ( row.UserID );

if ( users != null )

{

listUsers.Items.Add( users );

}

}



Hrcko
 
Hi,

Well first of all A little explanation of what is what would be helpful

I assume that db.dataSetAccounts.Users is a datatable , if so the
query you are using is not correct, a DatTable and/or dataset is not a DB
engine, meaning that you cannot use a subquery to get data from it.

In this case I think that you want to get all the users except nUserID

if this is the case use a DataView


DataView dv = new DataView ( db.dataSetAccounts.Users, "UserID <> " +
nUserID, DataViewCurrentRowStatus.CurrentRows);

Cheers,
 
I get an error on DataViewCurrentRowStatus.CurrentRows.

Hrcko


Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Well first of all A little explanation of what is what would be helpful

I assume that db.dataSetAccounts.Users is a datatable , if so
the query you are using is not correct, a DatTable and/or dataset is not
a DB engine, meaning that you cannot use a subquery to get data from it.

In this case I think that you want to get all the users except nUserID

if this is the case use a DataView


DataView dv = new DataView ( db.dataSetAccounts.Users, "UserID <> " +
nUserID, DataViewCurrentRowStatus.CurrentRows);

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Hrcko said:
what is wrong with this code ?


listUsers.DisplayMember = "UserName";

string UserIDSelect = "UserID not in "+ "(Select UserID "+

"From Users where Users.UserID ='"
+ nUserID + "'" + ")";


DataRow[] Urows = db.dataSetAccounts.Users.Select(UserIDSelect);

foreach ( DataSetAccounts.UsersRow row in Urows )

{

DataSetAccounts.UsersRow users =

db.dataSetAccounts.Users.FindByUserID ( row.UserID );

if ( users != null )

{

listUsers.Items.Add( users );

}

}



Hrcko
 
Back
Top