missing text in a label

T

Terry

Howdy,

I'm having trouble getting a message to appear in a label.

I have the following code snippet:

lbErrorMssg.Text = ""
foreach (DataRow Rrow in ds.Tables["ImportCSV"].Rows)
{
string sString = Rrow["EmployeeNumber"].ToString();
if (!ImportCSV.IsNumeric(sString))
{
lbErrorMssg.Text = lbErrorMssg.Text + "EmployeeNumber " + sString +
"is not an integer. Please verify the EmployeeNumber." + "<BR>";
}
}

I know that this is catching non numeric entries because the label is
populated with as many error messages as I put errors in the text
data. However, the text of sString never appears in lbErrorMssg. I
replaced sString with Rrow["EmployeeNumber"].ToString(); but there was
no change. How can I make the value for the invalid EmployeeNumber
appear in the text of lbErrorMessage?

In case you are wondering what is "IsNumeric", it is a custom function
I made to mimic the built in IsNumeric function of vbscript, or isnan
from javascript.

--Terry
 
M

Martin Dechev

Hi, Terry,

Did you try to debug the code? What is the value of sString shown in the
debugger? Maybe it is an empty string. Try printing sString.Length.

Hope this helps
Martin
 
T

Terry

Martin,

If I step through the code the locals window displays every
EmployeeNumber value for the line "string sString =
Rrow["EmployeeNumber"].ToString();",
unless the value is not numeric. so I see something like

sString = "597308"
sString = "597309"
sString = "597310"
sString = "597311"

Until I hit a non numeric value such as 59xxxx, and then I see
sString = ""

I do not understand why the value goes to "" at that point. It is not
as if the DataSet is strongly typed. I generate the DataSet with a
simple ODBC query,

string ConnectionString = @"Driver={Microsoft Text Driver (*.txt;
*.csv)};DBQ=c:\";
string sSQL = "SELECT EmployeeNumber, FName, LName, Site FROM " +
FileName;
OdbcConnection conn = new OdbcConnection(ConnectionString);
try
{
conn.Open();
OdbcDataAdapter da = new OdbcDataAdapter(sSQL, conn);
da.Fill(ds,"ImportCSV");
}

It seems like all the fields would default to string so the switch
from a numeric to non numeric value is no problem????

What am I missing?

--Terry


Martin Dechev said:
Hi, Terry,

Did you try to debug the code? What is the value of sString shown in the
debugger? Maybe it is an empty string. Try printing sString.Length.

Hope this helps
Martin
Terry said:
Howdy,

I'm having trouble getting a message to appear in a label.

I have the following code snippet:

lbErrorMssg.Text = ""
foreach (DataRow Rrow in ds.Tables["ImportCSV"].Rows)
{
string sString = Rrow["EmployeeNumber"].ToString();
if (!ImportCSV.IsNumeric(sString))
{
lbErrorMssg.Text = lbErrorMssg.Text + "EmployeeNumber " + sString +
"is not an integer. Please verify the EmployeeNumber." + "<BR>";
}
}

I know that this is catching non numeric entries because the label is
populated with as many error messages as I put errors in the text
data. However, the text of sString never appears in lbErrorMssg. I
replaced sString with Rrow["EmployeeNumber"].ToString(); but there was
no change. How can I make the value for the invalid EmployeeNumber
appear in the text of lbErrorMessage?

In case you are wondering what is "IsNumeric", it is a custom function
I made to mimic the built in IsNumeric function of vbscript, or isnan
from javascript.

--Terry
 

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

Top