473,394 Members | 1,787 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,394 software developers and data experts.

System.FormatException: Input String was not in a correct format.

I've got an error "System.FormatException: 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(sender As Object, e As EventArgs)
DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
DataGrid1.DataBind()
End Sub

Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
Dim connectionString As String = "server='localhost'; user id='******';
password='******'; database='******'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
([Software].[Others] like @Others)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_others As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_others.ParameterName = "@Others" dbParam_others.Value = others
dbParam_others.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_others)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet

End Function
Nov 18 '05 #1
2 11100
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***************@tk2msftngp13.phx.gbl...
I've got an error "System.FormatException: 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(sender As Object, e As EventArgs)
DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
DataGrid1.DataBind()
End Sub

Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
Dim connectionString As String = "server='localhost'; user id='******'; password='******'; database='******'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
([Software].[Others] like @Others)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_others As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_others.ParameterName = "@Others" dbParam_others.Value = others
dbParam_others.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_others)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(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***************@tk2msftngp13.phx.gbl...
I've got an error "System.FormatException: 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(sender As Object, e As EventArgs)
DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
DataGrid1.DataBind()
End Sub

Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
Dim connectionString As String = "server='localhost'; user id='******'; password='******'; database='******'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
([Software].[Others] like @Others)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_others As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_others.ParameterName = "@Others" dbParam_others.Value = others
dbParam_others.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_others)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(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
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...
1
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
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...
14
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...
10
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
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....
0
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...
1
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...
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
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.