PC Review


Reply
Thread Tools Rate Thread

Comparing Dataset values with Strings

 
 
=?Utf-8?B?S3VuYWwgU2Vu?=
Guest
Posts: n/a
 
      16th Feb 2005
I am creating a login screen wherein only certain users are granted
permission. The names of those users,are copied into a dataset using
dataadapter.Then the dataview is used.

But the problem here is that the "Dv.Count" always evaluates ..to 0. Hence
whenever I enter the valid names "Invalid User" is prompted on the screen

I have writen the code below.

OleDbDataAdapter dAdap1 = new OleDbDataAdapter("SELECT ..[EMPLOYEE ID] FROM
EMPLOYEE;",con1);

dAdap1.Fill(DtSet);

Dv.Table=DtSet.Tables["EMPLOYEE"];

Dv.RowFilter.CompareTo(txtLogin.Text);

if(Dv.Count==0)

{

txtLogin.Text="Invalid User";

}

Kindly suggest,


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      16th Feb 2005
Kunal,

In my opinion do you take a difficult approach for this.

Probably you can use a command executescalar to get a count when that is 0
the Id is wrong.

http://msdn.microsoft.com/library/de...calartopic.asp

This is when you don't do password testing what I did not see now in your
method.
(Although than you can use the WHERE AND)

I hope this helps?

Cor


 
Reply With Quote
 
=?Utf-8?B?QnJpYW4gQnJvd24=?=
Guest
Posts: n/a
 
      16th Feb 2005
Hi Kunal,

I believe that your problem lies with setting the rowfilter property of the
dataveiw. You are currently using the CompareTo() method (which is a string
method) when you need to be setting this property. You can set it like:

Dv.RowFilter = "columnname = 'columntextvalue'";

so all you have to do for a comparison is place the value of what you want
to match in the columntextvalue and it will reduce your rows.

If you are looking for this to be secure you should take a look at the
Microsoft Patterns and Practices Security guides at

http://www.microsoft.com/resources/p.../security.mspx

to get a good handle on what the latest techniques are.

I hope this helps.
-------------------------------
 
Reply With Quote
 
Andrew Conrad
Guest
Posts: n/a
 
      16th Feb 2005
You are comparing the txtLogin to the string which represents the
expressions which is used as a rowfilter for the DataView.
You will actually need to set the RowFilter to a expression which does the
comparision you require.

Andrew Conrad
Microsoft Corp
http://blogs.msdn.com/aconrad/

 
Reply With Quote
 
John Smith
Guest
Posts: n/a
 
      17th Feb 2005
Hi kunal,

I think you want to check for an existence of a user. Try the following (its
in vb with sql classes, but your can figure out how to do it in C# with your
oledb source)

Since you want to check, and only check, you need to read, so you can use a
DataReader.

Dim dr as sqlDataReader
Dim cm as new sqlCommand("SELECT UserName FROM tbUser", cn)

cn.open()
dr = cm.ExecuteReader()

do while dr.Read
if txtUsername.Text = CStr(dr("UserName")) then -- In vb, CStr casts the
value to String
' User found
end if
loop

Dont forget to close your datareader and dispose your connection when your
are done.

Ps. This code was not tested

"Kunal Sen" <Kunal (E-Mail Removed)> wrote in message
news:072DFA3C-D264-4F2B-B56F-(E-Mail Removed)...
>I am creating a login screen wherein only certain users are granted
> permission. The names of those users,are copied into a dataset using
> dataadapter.Then the dataview is used.
>
> But the problem here is that the "Dv.Count" always evaluates ..to 0. Hence
> whenever I enter the valid names "Invalid User" is prompted on the screen
>
> I have writen the code below.
>
> OleDbDataAdapter dAdap1 = new OleDbDataAdapter("SELECT ..[EMPLOYEE ID]
> FROM
> EMPLOYEE;",con1);
>
> dAdap1.Fill(DtSet);
>
> Dv.Table=DtSet.Tables["EMPLOYEE"];
>
> Dv.RowFilter.CompareTo(txtLogin.Text);
>
> if(Dv.Count==0)
>
> {
>
> txtLogin.Text="Invalid User";
>
> }
>
> Kindly suggest,
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Comparing strings Jon Skeet [C# MVP] Microsoft Dot NET Framework Forms 0 1st Dec 2006 10:58 PM
Comparing two strings Vycka Microsoft Dot NET Framework Forms 5 13th Sep 2004 09:56 PM
Comparing Strings with < Jonathan Rynd Microsoft Excel Worksheet Functions 3 31st Aug 2004 06:54 PM
Comparing Strings C# Learner Microsoft C# .NET 6 1st Mar 2004 07:21 PM
help with comparing strings.... Paul M Microsoft VB .NET 3 24th Feb 2004 06:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:11 AM.