HELP from Expert Needed!!! Problem using the find method in a DataView with multiple window forms

M

miggy

Greetings Experts,

Hopefully someone can help me out with this problem. I've been trying
to solve this problem for the past 10+ hours without any result. This
is my last resort. Someone please respond. I am a newbie to using
DataSet's and DataView's so I apologize in advance if my problem seems
a bit to easy.

Here's a overview of the problem:
I'm extracting the contents of an xml file into a DataSet. I then
create a DataView from the DataSet. I am using two forms. One form
is used to authenticate the user, username and password. The second
form has a text box that asks for the users SSN. What the program is
suppose to do is get that SSN and find it in the DataView to verify
the User. DataView has a method find() which lets you search through
the DataView to find a particular value. It will return a -1 if the
string is not found in the DataView otherwise, it has found a match
and will return the RowIndex of the matched string. These are the two
lines of codes that I am having problem with. Stmt 1 works, but stmt
doesn't work. I am concerned with stmt 2 because it is getting the
"num" from form 2:

int index = db.findSSN("111111111"); //stmt 1 returns the RowIndex
int index2 =db.findSSN(num); //stmt 2 returns -1

=====================================================================
DataView db = new DataView();

//ticket is an instance of form 2
//getSSN is a method in form 2 that returns a string value that is
given by the
//user in the textBox in form 2
string num = ticket.getSSN().ToString().Trim();

//will find the SSN in the database
public int findSSN(string ssn)
{
//sorts the dataview by ssn
//needed to use find
voters.Sort = "SSN";
//returns the rowIndex of the found string
int rowIndex = voters.Find(ssn);
int errorCode = 99;

//rowIndex returns -1 if no match found
if (rowIndex == -1) //if not found
{
//Not found in database
MessageBox.Show ("SSN not found in database.","District 15 Electronic
Voting",
MessageBoxButtons.OK,MessageBoxIcon.Error);

return errorCode;
}
else //returns the rowIndex of the record
{
return rowIndex;
}
}

stmt 1 works Correctly. But when I switched the string "11111111"
with num, the find method couldn't find it. I don't know why. I
checked to see if my DataView has the correct information and it does.
I believe my problem has something to do with using multiple forms
with the same DataView.

========================================================================
The only difference in the parametes is that one is explicit
("11111111") and the other is a variable (num). They should both give
me the same result.
I've been searching all day on the net and have found no clear
answers...
I wrote the method above separately and it worked. Once I added the
second form and used the txtBox contents as the input, my problem
began.
My first form is a login form, it authenticates the user. My second
form is when my app begins. That's when it stopped working.

Any posts, will be greatly appreciated!!

Miggy
email: (e-mail address removed)
 
M

Miha Markic

Hi,

What data type is SSN in DataTable?
I've created a table with an int (column1) and a string field (column2).

The folowing code works:
dataTable1.Rows.Add(new object[]{1, "1"});

dataTable1.Rows.Add(new object[]{2, "2"});

DataView dv = new DataView(dataTable1, string.Empty, "Column2 ASC",
DataViewRowState.CurrentRows);

Console.WriteLine(dv.Find(1));

Console.WriteLine(dv.Find("1"));



Both lines return index 0.
 
R

Rajesh.V

Using the tables command is much more friendly....

DataRow []drow = MyDataSet.Tables[0].Select("EmpPasswd = " +
strValueentered);

if drow.length is 0 then the password or similiarly the id is not there. Try
this out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top