473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Input String Not in Correct Format

I'm building a string to be used as the body of an email.

I'm getting this error message. "Input String Not In Correct Format".

I've checked several newsgroups, however, for the posts I found it was
always in conjunction with a query or conversion. This is neither.
It could be the control break I'm trying to use. I also tried
researching that but came up with a bunch of posts for web/window
controls that are breaking, rather than something to do with display of
text.

Here is the line of code that seems to be causing issues.
body = "The following payout is requested " &
Me.ddlType.SelectedValue.ToString & ": " & g_key & ". " & vbCrLf & _

Polite input is very welcome.
Thanks

Jan 16 '06 #1
7 2216
> always in conjunction with a query or conversion. This is neither.

That depends, conversion is possibly occuring. What data type is the
variable "g_key"? What is "body" -- the MailMessage.Body property or your own
variable? If it's your own variable what is it's data type?

Try the following:

body = "The following payout is requested " & Me.ddlType.SelectedValue & ":
" & Convert.ToString(g_key) & ". " & vbCrLf

Changes:
* Removed the .ToString() call on Me.ddlType.SelectedValue since
..SelectedValue is already a string
* Added an explicit convertion to string for g_key since it's data type is
not specified here.
* Remove the trailing ampersand and underscore (& _) after the visual basic
constant vbCrLf.

Paul

Jan 16 '06 #2
I made the changes you suggested. Here is the full code for that
string. It's still bombing out on that line.
Not quite sure why.
body = "The following payout is requested " & Me.ddlType.SelectedValue
& ": " & Convert.ToString(g_key) & ". " & vbCrLf & _
body = body & "Date Prepared: " & Now() & vbCrLf & _
body = body & "Date of Incident: " & Me.txtDtStart.Text &
vbCrLf & _
body = body & "Union: " & ddlUnion.SelectedValue & vbCrLf & _
body = body & "Reason: " & Me.ddlType.SelectedValue & vbCrLf &
"For the following employee(s):" & vbCrLf & vbCrLf

I split up the commands to build the string to make it easier to read
and debug.

Jan 16 '06 #3
Oh, and g_key is an integer.

Jan 16 '06 #4
Ok. I did notice that my line with

body = body & "Date Prepared: " & Now()

was causing a conversion error as well, so I changed that to: body =
body & "Date Prepared: " & Convert.ToString(Now() )

I'm still getting an error, however the stack trace has changed. I
dont' understand the error message "[InvalidCastException: Cast from
string "Date of Incident: 12/12/05" to type 'Boolean' is not valid.] ".
I don't know how this could be happening. This is the line references
'Date of Incident':

body = body & "Date of Incident: " & Me.txtDtStart.Text & vbCrLf & _

Here is the complete stack trace as I see it on the browser when
testing:

FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.DoubleType. Parse(String
Value, NumberFormatInfo NumberFormat)
Microsoft.VisualBasic.CompilerServices.DoubleType. Parse(String
Value)
Microsoft.VisualBasic.CompilerServices.BooleanType .FromString(String
Value)

[InvalidCastException: Cast from string "Date of Incident: 12/12/05
" to type 'Boolean' is not valid.]
Microsoft.VisualBasic.CompilerServices.BooleanType .FromString(String
Value)
GIS.InLieu.btnEmail_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\GIS\InLieu.aspx.vb:967
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
Thanks!

Jan 16 '06 #5
Never mind. I made a dumb error and did not remove the '& _' when I
changed how I built the string.

Jan 16 '06 #6
Maybe try making use of StringBuilder Class.
It would make life much more easier
Patrick

<tj*****@phenom-biz.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I'm building a string to be used as the body of an email.

I'm getting this error message. "Input String Not In Correct Format".

I've checked several newsgroups, however, for the posts I found it was
always in conjunction with a query or conversion. This is neither.
It could be the control break I'm trying to use. I also tried
researching that but came up with a bunch of posts for web/window
controls that are breaking, rather than something to do with display of
text.

Here is the line of code that seems to be causing issues.
body = "The following payout is requested " &
Me.ddlType.SelectedValue.ToString & ": " & g_key & ". " & vbCrLf & _

Polite input is very welcome.
Thanks

Jan 17 '06 #7
Like Patrick said, it's much more readable if you use a string builder. I'll
give it to you both ways:

body = "The following payout is requested " & _
Me.ddlType.SelectedValue & ": " & _
Convert.ToString(g_key) & ". " & vbCrLf & _
"Date Prepared: " & Now().ToShortDateString & vbCrLf & _
"Date of Incident: " & Me.txtDtStart.Text & vbCrLf & _
"Union: " & Me.ddlUnion.SelectedValue & vbCrLf & _
"Reason: " & Me.ddlType.SelectedValue & vbCrLf & _
"For the following employee(s):" & vbCrLf & vbCrLf

With a string builder:

Dim sb As New System.Text.StringBuilder
With sb
.Append("The following payout is requested ")
.Append(Me.ddlType.SelectedValue)
.Append(": ")
.Append(Convert.ToString(g_key))
.Append(". ")
.Append(vbCrLf)
.Append("Date Prepared: ")
.Append(Now().ToShortDateString)
.Append(vbCrLf)
.Append("Date of Incident: ")
.Append(Me.txtDtStart.Text)
.Append(vbCrLf)
.Append("Union: ")
.Append(Me.ddlUnion.SelectedValue)
.Append(vbCrLf)
.Append("Reason: ")
.Append(Me.ddlType.SelectedValue)
.Append(vbCrLf)
.Append("For the following employee(s):")
.Append(vbCrLf)
.Append(vbCrLf)
End With
MailMessage.Body = sb.ToString()

Jan 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
im using asp.net, C# to enter data into a table in sql server...however im getting this error: Input string was not in a correct format. Description: An unhandled exception occurred during the...
0
by: lianfe_ravago | last post by:
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...
5
by: blackg | last post by:
Input string not in correct format -------------------------------------------------------------------------------- I am trying to view a picture from a table. I am getting this error Input string...
1
by: amitbadgi | last post by:
Welcome back amitbadgi | Logout | Faq Knowledge Discovery Keys COMPUTER PROGRAMMING, DATA MINING, STATISTICS, ARTIFICIAL INTELLIGENCE * Settings * Photos * Lists * MVPs * Forums * Blogs
1
by: amitbadgi | last post by:
I am gettign this error, while migration an app to asp.net Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 19: Dim enddate =...
0
by: hudhuhandhu | last post by:
have got an error which says Input string was not in a correct format. as follows.. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
1
by: sehguh | last post by:
Hello folks I have recently been studying a book called "sams teach yourself asp.net 2.0 in24 hours by scott mitchell. I have reached page 614 but when i tried to run an asp page called...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.