How to use the DataTable.Select?

  • Thread starter Thread starter Jason Huang
  • Start date Start date
J

Jason Huang

Hi,

I am trying to build a Login web form. I have one TextBoxAccount, and one
Password1 in the web form.
And the database table is User. No

DataRow[] FRow;
FRow = DS.Tables["User"].Select("UsrID= @TextBoxAccount.Text and PassWd=
@Password1.Value " );
if (FRow != null )
{
LabelAccount.Text="Identified!";
LabelPassword.Text="Identified!";
}
else
{
LabelAccount.Text =" Unknown";
LabelPassword.Text =" Unknown";
}

However, it is not working as I planed.
Would someone give me some advice?
Thanks.

Jason
 
Hi,

Without testing myself, i suspect the Select method does not fill in the
values of your parameters ;

I suggest you build your filter expression first and then pass it,

string selectString = "UsrID=" + TextBoxAccount.Text + " and PassWd=" +
Password1.Value;
FRow = DS.Tables["User"].Select(selectString);
....

Also you might consider to build a try catch block around your Select to
catch possible exceptions ;
they do help a lot in clarifying a problem (not specifically this problem)

Hope this helps,

AinO.
 
Thanks!
I think I missed the "'" before and after the TextBoxAccount.Text!

AinO said:
Hi,

Without testing myself, i suspect the Select method does not fill in the
values of your parameters ;

I suggest you build your filter expression first and then pass it,

string selectString = "UsrID=" + TextBoxAccount.Text + " and PassWd=" +
Password1.Value;
FRow = DS.Tables["User"].Select(selectString);
...

Also you might consider to build a try catch block around your Select to
catch possible exceptions ;
they do help a lot in clarifying a problem (not specifically this problem)

Hope this helps,

AinO.

Jason Huang said:
Hi,

I am trying to build a Login web form. I have one TextBoxAccount, and
one
Password1 in the web form.
And the database table is User. No

DataRow[] FRow;
FRow = DS.Tables["User"].Select("UsrID= @TextBoxAccount.Text and
PassWd=
@Password1.Value " );
if (FRow != null )
{
LabelAccount.Text="Identified!";
LabelPassword.Text="Identified!";
}
else
{
LabelAccount.Text =" Unknown";
LabelPassword.Text =" Unknown";
}

However, it is not working as I planed.
Would someone give me some advice?
Thanks.

Jason
 
Back
Top