Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Saturday, March 31, 2012

String Stripping

Hi,

I am trying to create a page that will check user input against a value in database. This page will have a text box for user to enter serial #.
Serial # length is variable but last 3 digit is always number.
For examples:
W04051234-PAY001 in this example code is 1234-PAY
W05051234-PAT002 in this example code is 1234-PAT

A12056040-G001 in this example code is 6040-G
B11056080-SU001 in this example code is 6080-s

Which is the best approach to extract CODE from user input?

Any help will be appriciated.

Thank

TekinUse the Regular Expression class, RegExp with a regular expression that looks for:
4 digits (or is it 3?) followed by
dash
followed by 1 or letters

That expression is:
\d{4}\-[A-Za-z]+
Actually,

I would like to Trancate first 5 digits and last 3 digits.

For examples:
W04051234-PAY001 in this example code is 1234-PAY
If you are attempting to strip a specific group of characters, the String class has numerous useful methods. I encourage you to read about the String class in the .net docs. I think the SubString() and Length() methods will be useful.

String to Int error

Hello,

I need to convert a value from my textbox from string to int. It only hold the idea of an item and i need to send that as Stored Procedure value to fetch another value.
I now get the current error:

Input string was not in a correct format.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.FormatException: Input string was not in a correct format.

Source Error:

Line 97: Dim strComm As String = "spQMelderStatusGet"
Line 98: Dim str As String = Convert.ToString(lblStatus.Text)
Line 99: Dim ID As Int32 = Int32.Parse(str)
Line 100: Using loStat As SqlCommand = New SqlCommand(strComm)
Line 101:


Source File:D:\Source\Qualm\QMelder\StatusViewer.aspx.vb Line:99

And this is the code i'm using:

'Get status naamDim strCommAs String ="spQMelderStatusGet"Dim strAs String = Convert.ToString(lblStatus.Text)
Dim IDAs Int32 = Int32.Parse(str)
Using loStatAs SqlCommand =New SqlCommand(strComm)

Dim StatIDAs New SqlParameter()
StatID.ParameterName ="@dotnet.itags.org.StatusID" StatID.SqlDbType = SqlDbType.Int StatID.Direction = ParameterDirection.InputOutput StatID.Size = 2 StatID.Value = ID loStat.Parameters.Add(StatID) loStat.Connection = loConn loStat.CommandType = CommandType.StoredProcedure statReader = loStat.ExecuteReader lblStatus.Text = statReader("StatusNaam")
End Using

statReader.Close()


I've tried all kinds of ways, like converting the txtbox value to string and then to int but keep giving the same error, so most likely those codes weren't the right ones either.

If someone could help me out, tnx alot in advance.

Anoiks

Hi

before parsing String value in integer, check it's value ..

i hope . in ur case it's value is NULL or any Literal word


Hi

Hope I have understood your problem correctly.

Have you tried Convert.ToInt32("string").

But as I write, If the parse function you used fails to convert the string to integer, then may be the value entered in the text box either is non-convertible to integer data type or a conversion results in a out of range value. If you beleive it is a large integer value, can you try using a "float" or a "double" data type.

Worse case, can you convert your stored procedure type to accept an integer, I hope that is not hindering your requirement.

VJ


ok that was a stupid mistake, thanks alot i was too focussed on that part of code.
So i didnt notice i didnt fill the string in codes before that.Geeked

Wednesday, March 28, 2012

String was not recognized as a valid DateTime.

I am capturing a value from a text field and insert it into database of data type DateTime. I have used Convert.ToDateTime("stringdate") to convert it into datetime but i get the above error. But when I converted DateTime value to string and then converted it into DateTime using above method it works fine. I don't know what I need to do.

thanx for any helpIt's likely because the DateTime class can't figure out what date format the string is in. If you use DateTime.Parse that might work or if you always know what format your string is in use DateTime.ParseExact, because with that you can specify the date format.
Try:

FromDate = Convert.ToDateTime(Request.Form["FromDate"].ToString()).Date;

Where FromDate is the txtField - I had trouble with this - Seems like going around the houses a bit to me, but it works.

Pete

String. Is this Possible? Still trying to figure this out after 4 hours. Thank You.

Hello,
I am changing the property of a control:
myMenu.Item(0).Item(1).Text = "Something"
What I want is to use the path which value is in a string. Something like:
Dim path As String = ".Item(0).Item(1)."
Now I would to the following:
myMenu & path & Text = "Something"
Of course this doesn't work.
Any ideas?
Thank You,
Miguel

There is no simple solution that will enable that idea to work. Youcould get it to work using a utility method that parses the path string, and then attempts to find the various properties within that string. However, that would be a needlessly slow, complex, and error-prone way to find a control.
Whatever it is that you're trying to achieve, you should perhaps reconsider it. I'm sure you'll come up with a simpler solution.

String.Replace() in .net 1.1 did not work!

Hi, guys,

The following source code in Page_Load() did not work:

string pathVal = "2006\";
pathVal.Replace("\\", "/");

I still had the value "2006\", not "2006/", the one I expected.

I then tried the second line as:

pathVal.Replace('\', '/');

still no luck.

Any ideas? Thanks.Replace probably returns a new string that you need to set a variable to.

"Andrew" <Andrew@.discussions.microsoft.com> wrote in message
news:74E97D68-79AC-47AB-B2D3-802DF9579D77@.microsoft.com...
> Hi, guys,
> The following source code in Page_Load() did not work:
> string pathVal = "2006\";
> pathVal.Replace("\\", "/");
> I still had the value "2006\", not "2006/", the one I expected.
> I then tried the second line as:
> pathVal.Replace('\', '/');
> still no luck.
> Any ideas? Thanks.
You need to get the value value returned by Replace function. It returns
stirng variable.
"Andrew" <Andrew@.discussions.microsoft.com> wrote in message
news:74E97D68-79AC-47AB-B2D3-802DF9579D77@.microsoft.com...
> Hi, guys,
> The following source code in Page_Load() did not work:
> string pathVal = "2006\";
> pathVal.Replace("\\", "/");
> I still had the value "2006\", not "2006/", the one I expected.
> I then tried the second line as:
> pathVal.Replace('\', '/');
> still no luck.
> Any ideas? Thanks.
String.Replace() returns a new String value. You can always set the
returned value to the original string.

String.Replace() in .net 1.1 did not work!

Hi, guys,
The following source code in Page_Load() did not work:
string pathVal = "2006\";
pathVal.Replace("\\", "/");
I still had the value "2006\", not "2006/", the one I expected.
I then tried the second line as:
pathVal.Replace('\', '/');
still no luck.
Any ideas? Thanks.Replace probably returns a new string that you need to set a variable to.
"Andrew" <Andrew@.discussions.microsoft.com> wrote in message
news:74E97D68-79AC-47AB-B2D3-802DF9579D77@.microsoft.com...
> Hi, guys,
> The following source code in Page_Load() did not work:
> string pathVal = "2006\";
> pathVal.Replace("\\", "/");
> I still had the value "2006\", not "2006/", the one I expected.
> I then tried the second line as:
> pathVal.Replace('', '/');
> still no luck.
> Any ideas? Thanks.
>
You need to get the value value returned by Replace function. It returns
stirng variable.
"Andrew" <Andrew@.discussions.microsoft.com> wrote in message
news:74E97D68-79AC-47AB-B2D3-802DF9579D77@.microsoft.com...
> Hi, guys,
> The following source code in Page_Load() did not work:
> string pathVal = "2006\";
> pathVal.Replace("\\", "/");
> I still had the value "2006\", not "2006/", the one I expected.
> I then tried the second line as:
> pathVal.Replace('', '/');
> still no luck.
> Any ideas? Thanks.
>
String.Replace() returns a new String value. You can always set the
returned value to the original string.

Tuesday, March 13, 2012

stuck on this one

I'm trying to find a label and the value within a datalist, i've done this i
n
the passed in the datalist_itemdatbound routine and worked likes a charm. No
w
I"m trying to do the samething in a seperate routine and I can't find the
value.
in the routine i'm getting the value of the checkbox, checked or not and
passing that correctly, I also want to the get a the value of the associated
label with the checkbox and i can't get that working.
I have this:
for I = o to datalist.items.count - 1
checked = datalist.items(I).findcontrol("checkbox")
text = datatlist.items(I).findcontrol("labelname")
value = value & checked.checked.tostring() & text.text.tostring()
next
i'm getting the checkbox value but not the text value.
any ideas why this is happening?I writing this in the C#. You will be able to convert it to the VB
CheckBox cb = (CheckBox)datalist.items[i].Controls.FindControl("checkbox");
bool cval = cb.Checked;
Label lbl = (Label)datalist.items[i].Controls.FindControl("label");
also you can use code like this:
CheckBox cb = (CheckBox)datalist.items[i].Controls[0];
bool cval = cb.Checked;
Label lbl = (Label)datalist.items[i].Controls[1];
in the C# the first control is 0 and in the VB the first control is 1
if your listItem has two controls you have to try to find control 1 and 2
bye
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:F6EFC19C-B103-42DA-9B71-F09A8559C54A@.microsoft.com...
> I'm trying to find a label and the value within a datalist, i've done this
in
> the passed in the datalist_itemdatbound routine and worked likes a charm.
Now
> I"m trying to do the samething in a seperate routine and I can't find the
> value.
> in the routine i'm getting the value of the checkbox, checked or not and
> passing that correctly, I also want to the get a the value of the
associated
> label with the checkbox and i can't get that working.
> I have this:
> for I = o to datalist.items.count - 1
> checked = datalist.items(I).findcontrol("checkbox")
> text = datatlist.items(I).findcontrol("labelname")
> value = value & checked.checked.tostring() & text.text.tostring()
> next
> i'm getting the checkbox value but not the text value.
> any ideas why this is happening?
>
thats simialar to what i have and i can't get the label to be recognized:
For I = 0 To datalist.Items.Count - 1
checkbox= dlScores.Items(I).FindControl("chkStuff")
CarInformation= dlScores.Items(G).FindControl("CarStuff")
value = value & checkbox.Checked.ToString() & "|" &
CarInformation.text & "|"
Next I
"Michael Tkachev" wrote:

> I writing this in the C#. You will be able to convert it to the VB
> CheckBox cb = (CheckBox)datalist.items[i].Controls.FindControl("checkbox");
> bool cval = cb.Checked;
> Label lbl = (Label)datalist.items[i].Controls.FindControl("label");
> also you can use code like this:
> CheckBox cb = (CheckBox)datalist.items[i].Controls[0];
> bool cval = cb.Checked;
> Label lbl = (Label)datalist.items[i].Controls[1];
> in the C# the first control is 0 and in the VB the first control is 1
> if your listItem has two controls you have to try to find control 1 and 2
> bye
> "Mike" <Mike@.discussions.microsoft.com> wrote in message
> news:F6EFC19C-B103-42DA-9B71-F09A8559C54A@.microsoft.com...
> in
> Now
> associated
>
>

stuck on this one

I'm trying to find a label and the value within a datalist, i've done this in
the passed in the datalist_itemdatbound routine and worked likes a charm. Now
I"m trying to do the samething in a seperate routine and I can't find the
value.
in the routine i'm getting the value of the checkbox, checked or not and
passing that correctly, I also want to the get a the value of the associated
label with the checkbox and i can't get that working.

I have this:
for I = o to datalist.items.count - 1
checked = datalist.items(I).findcontrol("checkbox")
text = datatlist.items(I).findcontrol("labelname")
value = value & checked.checked.tostring() & text.text.tostring()
next

i'm getting the checkbox value but not the text value.

any ideas why this is happening?I writing this in the C#. You will be able to convert it to the VB

CheckBox cb = (CheckBox)datalist.items[i].Controls.FindControl("checkbox");
bool cval = cb.Checked;
Label lbl = (Label)datalist.items[i].Controls.FindControl("label");

also you can use code like this:

CheckBox cb = (CheckBox)datalist.items[i].Controls[0];
bool cval = cb.Checked;
Label lbl = (Label)datalist.items[i].Controls[1];

in the C# the first control is 0 and in the VB the first control is 1
if your listItem has two controls you have to try to find control 1 and 2

bye

"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:F6EFC19C-B103-42DA-9B71-F09A8559C54A@.microsoft.com...
> I'm trying to find a label and the value within a datalist, i've done this
in
> the passed in the datalist_itemdatbound routine and worked likes a charm.
Now
> I"m trying to do the samething in a seperate routine and I can't find the
> value.
> in the routine i'm getting the value of the checkbox, checked or not and
> passing that correctly, I also want to the get a the value of the
associated
> label with the checkbox and i can't get that working.
> I have this:
> for I = o to datalist.items.count - 1
> checked = datalist.items(I).findcontrol("checkbox")
> text = datatlist.items(I).findcontrol("labelname")
> value = value & checked.checked.tostring() & text.text.tostring()
> next
> i'm getting the checkbox value but not the text value.
> any ideas why this is happening?
thats simialar to what i have and i can't get the label to be recognized:

For I = 0 To datalist.Items.Count - 1
checkbox= dlScores.Items(I).FindControl("chkStuff")
CarInformation= dlScores.Items(G).FindControl("CarStuff")
value = value & checkbox.Checked.ToString() & "|" &
CarInformation.text & "|"
Next I

"Michael Tkachev" wrote:

> I writing this in the C#. You will be able to convert it to the VB
> CheckBox cb = (CheckBox)datalist.items[i].Controls.FindControl("checkbox");
> bool cval = cb.Checked;
> Label lbl = (Label)datalist.items[i].Controls.FindControl("label");
> also you can use code like this:
> CheckBox cb = (CheckBox)datalist.items[i].Controls[0];
> bool cval = cb.Checked;
> Label lbl = (Label)datalist.items[i].Controls[1];
> in the C# the first control is 0 and in the VB the first control is 1
> if your listItem has two controls you have to try to find control 1 and 2
> bye
> "Mike" <Mike@.discussions.microsoft.com> wrote in message
> news:F6EFC19C-B103-42DA-9B71-F09A8559C54A@.microsoft.com...
> > I'm trying to find a label and the value within a datalist, i've done this
> in
> > the passed in the datalist_itemdatbound routine and worked likes a charm.
> Now
> > I"m trying to do the samething in a seperate routine and I can't find the
> > value.
> > in the routine i'm getting the value of the checkbox, checked or not and
> > passing that correctly, I also want to the get a the value of the
> associated
> > label with the checkbox and i can't get that working.
> > I have this:
> > for I = o to datalist.items.count - 1
> > checked = datalist.items(I).findcontrol("checkbox")
> > text = datatlist.items(I).findcontrol("labelname")
> > value = value & checked.checked.tostring() & text.text.tostring()
> > next
> > i'm getting the checkbox value but not the text value.
> > any ideas why this is happening?
>