473,545 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.FormatEx ception: Input String was not in a correct format.

I've got an error "System.FormatE xception: Input string was not in a correct
format." while I'm implementing a datagrid and a textbox
What's wrong with it?

Sub Button1_Click(s ender As Object, e As EventArgs)
DataGrid1.DataS ource = MyQueryMethod(C Int(TextBox1.Te xt))
DataGrid1.DataB ind()
End Sub

Function MyQueryMethod(B yVal others As String) As System.Data.Dat aSet
Dim connectionStrin g As String = "server='localh ost'; user id='******';
password='***** *'; database='***** *'"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Sql Client.SqlConne ction(connectio nString)
Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
([Software].[Others] like @Others)"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Sql Client.SqlComma nd
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection
Dim dbParam_others As System.Data.IDa taParameter = New
System.Data.Sql Client.SqlParam eter
dbParam_others. ParameterName = "@Others" dbParam_others. Value = others
dbParam_others. DbType = System.Data.DbT ype.String
dbCommand.Param eters.Add(dbPar am_others)

Dim dataAdapter As System.Data.IDb DataAdapter = New
System.Data.Sql Client.SqlDataA dapter
dataAdapter.Sel ectCommand = dbCommand
Dim dataSet As System.Data.Dat aSet = New System.Data.Dat aSet
dataAdapter.Fil l(dataSet)
Return dataSet

End Function
Nov 18 '05 #1
2 11108
I would guess it is something to do with converting the TextBox1.Text to an
int data type. The textbox could potentially contain a value other than a
numeric value. This would cause this error. Also, MyQueryMethod looks like
it is expecting a value of a string data type. Since you are converting
TextBox1.Text to an int type, this may also cause the error.

-Darrin
"sbox" <s@b.x> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
I've got an error "System.FormatE xception: Input string was not in a correct format." while I'm implementing a datagrid and a textbox
What's wrong with it?

Sub Button1_Click(s ender As Object, e As EventArgs)
DataGrid1.DataS ource = MyQueryMethod(C Int(TextBox1.Te xt))
DataGrid1.DataB ind()
End Sub

Function MyQueryMethod(B yVal others As String) As System.Data.Dat aSet
Dim connectionStrin g As String = "server='localh ost'; user id='******'; password='***** *'; database='***** *'"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Sql Client.SqlConne ction(connectio nString)
Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
([Software].[Others] like @Others)"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Sql Client.SqlComma nd
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection
Dim dbParam_others As System.Data.IDa taParameter = New
System.Data.Sql Client.SqlParam eter
dbParam_others. ParameterName = "@Others" dbParam_others. Value = others
dbParam_others. DbType = System.Data.DbT ype.String
dbCommand.Param eters.Add(dbPar am_others)

Dim dataAdapter As System.Data.IDb DataAdapter = New
System.Data.Sql Client.SqlDataA dapter
dataAdapter.Sel ectCommand = dbCommand
Dim dataSet As System.Data.Dat aSet = New System.Data.Dat aSet
dataAdapter.Fil l(dataSet)
Return dataSet

End Function

Nov 18 '05 #2
You should not have the ' ' in your connection string. Take a look at the
connection strings at

http://www.able-consulting.com/dotne...anagedProvider

Ben Miller

--
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"sbox" <s@b.x> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
I've got an error "System.FormatE xception: Input string was not in a correct format." while I'm implementing a datagrid and a textbox
What's wrong with it?

Sub Button1_Click(s ender As Object, e As EventArgs)
DataGrid1.DataS ource = MyQueryMethod(C Int(TextBox1.Te xt))
DataGrid1.DataB ind()
End Sub

Function MyQueryMethod(B yVal others As String) As System.Data.Dat aSet
Dim connectionStrin g As String = "server='localh ost'; user id='******'; password='***** *'; database='***** *'"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Sql Client.SqlConne ction(connectio nString)
Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
([Software].[Others] like @Others)"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Sql Client.SqlComma nd
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection
Dim dbParam_others As System.Data.IDa taParameter = New
System.Data.Sql Client.SqlParam eter
dbParam_others. ParameterName = "@Others" dbParam_others. Value = others
dbParam_others. DbType = System.Data.DbT ype.String
dbCommand.Param eters.Add(dbPar am_others)

Dim dataAdapter As System.Data.IDb DataAdapter = New
System.Data.Sql Client.SqlDataA dapter
dataAdapter.Sel ectCommand = dbCommand
Dim dataSet As System.Data.Dat aSet = New System.Data.Dat aSet
dataAdapter.Fil l(dataSet)
Return dataSet

End Function

Nov 18 '05 #3

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

Similar topics

2
1144
by: MrMike | last post by:
This problably has a very simple explanation but it is totally perplexing me. I have the following code... Dim CompletelyUsed As String CompletelyUsed = Me.txtCompletelyUsed.Text Select Case CompletelyUsed Case "Y" Or "y" Do 'Do something here Case "N" Or "n"
1
7758
by: .YC | last post by:
Hi, I was trying on the following code n I got an exception. Can anyone tell me whats wrong? using System; namespace Module_2 { /// <summary>
0
1431
by: zee | last post by:
System.FormatException: Input string was not in a correct format. I am inputting into a databse the value that causes an error is a double, If I leave that field blank then I catch the exception it doesnt instead I get the above error. Why cant I catch this exception? zee *** Sent via Developersdex http://www.developersdex.com *** Don't...
14
3645
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style of date formatting (RFC 822). I have been using a variation of RFC 1123 (just change the time zone to an offset, i.e. "-0800"). It seems to be...
10
12207
by: tshad | last post by:
I have a problem setting the background color of textbox on the fly. I tried using: applicantID.backcolor = "F6F6F6" and applicantID.backcolor = "#F6F6F6"
2
10885
by: Simon Harris | last post by:
I have created a web service, which when I call in my browser presents the text form etc. When I click the button, I get this error: System.ArgumentException: Cannot convert to System.Int32. Parameter name: type ---> System.FormatException: Input string was not in a correct format. at System.Number.ParseInt32(String s, NumberStyles style,...
0
3110
by: bnlockwood | last post by:
G'day all, Thank you in advance for anyone that can help. I have a shopping cart datagrid on my c# asp.net page. This is the code: ------------------------------------- <asp:datagrid id="grdShoppingCart" OnItemDataBound="ItemDB"
1
5151
by: Ratz | last post by:
Hello everyone! I'm new to this Forum! I've spent about 56 hours trying to solve a .NET VB Runtime error while Using a program.Ive contacted the developer of the program and he could not figure out why i'm getting these errors! SO i have come here for the Help from the GURUS! here is one message that pops up! See the end of this message for...
1
4741
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 THE PROGRAM PLEASE HELP ME Server Error in '/WebApplication1' Application....
0
7478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7437
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5984
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.