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

Input string incorrect format

Here is my code below. I recieve this error when I run

MyCommand.SelectCommand.ExecuteNonQuery()

Thanks. Big E

Sub MyDataGrid_Update(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)

Dim DS As DataSet

Dim Portal As String =
ConfigurationSettings.AppSettings("Portal.Connecti onString")

Dim cnPortal As SqlConnection = New SqlConnection(Portal)

Dim MyCommand As SqlDataAdapter = New SqlDataAdapter("spDGAnswer_Update",
cnPortal)

MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@AnswerId",
SqlDbType.Int))

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@AnswerDesc",
SqlDbType.VarChar, 50))

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@SortOrder",
SqlDbType.TinyInt))

MyCommand.SelectCommand.Parameters("@AnswerId").Va lue =
MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))

Dim Cols As String() = {"@AnswerId", "@AnswerDesc", "@SortOrder"}

Dim NumCols As Integer = E.Item.Cells.Count

Dim I As Integer

For I = 1 To NumCols - 1 'skip first, second and last column

Dim CurrentTextBox As TextBox

CurrentTextBox = E.Item.Cells(I).Controls(0)

Dim ColValue As String = CurrentTextBox.Text

MyCommand.SelectCommand.Parameters(Cols(I - 1)).Value =
Server.HtmlEncode(ColValue)

Next

MyCommand.SelectCommand.Connection.Open()

Try

MyCommand.SelectCommand.ExecuteNonQuery()

MyDataGrid.EditItemIndex = -1

Catch Exp As SqlException

If Exp.Number = 2627 Then

Message.InnerHtml = "ERROR: A record already exists with the same primary
key"

' Else

' Message.InnerHtml = "ERROR: Could not update record, please ensure the
fields are correctly filled out"

End If

Message.Style("color") = "red"

End Try

MyCommand.SelectCommand.Connection.Close()

BindGrid()

End Sub
Nov 18 '05 #1
1 1888
look at the SelectCommand, what's it's SQL statement look like? the SPROC if
it's using.
Are the params you are passing in the right TYPE?

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Big E" <no****@nospam.com> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
Here is my code below. I recieve this error when I run

MyCommand.SelectCommand.ExecuteNonQuery()

Thanks. Big E

Sub MyDataGrid_Update(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)

Dim DS As DataSet

Dim Portal As String =
ConfigurationSettings.AppSettings("Portal.Connecti onString")

Dim cnPortal As SqlConnection = New SqlConnection(Portal)

Dim MyCommand As SqlDataAdapter = New SqlDataAdapter("spDGAnswer_Update",
cnPortal)

MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@AnswerId",
SqlDbType.Int))

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@AnswerDesc",
SqlDbType.VarChar, 50))

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@SortOrder",
SqlDbType.TinyInt))

MyCommand.SelectCommand.Parameters("@AnswerId").Va lue =
MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))

Dim Cols As String() = {"@AnswerId", "@AnswerDesc", "@SortOrder"}

Dim NumCols As Integer = E.Item.Cells.Count

Dim I As Integer

For I = 1 To NumCols - 1 'skip first, second and last column

Dim CurrentTextBox As TextBox

CurrentTextBox = E.Item.Cells(I).Controls(0)

Dim ColValue As String = CurrentTextBox.Text

MyCommand.SelectCommand.Parameters(Cols(I - 1)).Value =
Server.HtmlEncode(ColValue)

Next

MyCommand.SelectCommand.Connection.Open()

Try

MyCommand.SelectCommand.ExecuteNonQuery()

MyDataGrid.EditItemIndex = -1

Catch Exp As SqlException

If Exp.Number = 2627 Then

Message.InnerHtml = "ERROR: A record already exists with the same primary
key"

' Else

' Message.InnerHtml = "ERROR: Could not update record, please ensure the
fields are correctly filled out"

End If

Message.Style("color") = "red"

End Try

MyCommand.SelectCommand.Connection.Close()

BindGrid()

End Sub

Nov 18 '05 #2

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

Similar topics

9
by: Arnold | last post by:
I need to read a binary file and store it into a buffer in memory (system has large amount of RAM, 2GB+) then pass it to a function. The function accepts input as 32 bit unsigned longs (DWORD). I...
7
by: Don Riesbeck Jr. | last post by:
I'm working on an application (OEM) using C# that utilizes input from a keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device, and input from it is sent to the system as if it...
6
by: JohnnyW | last post by:
Hello, I have I simple question that is not clear for me. So, I have a input field (text field) in my html page. User should give input as a string like following 12 345 678,0 If user gives...
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: ndawg123 | last post by:
Hey guys what im trying to do is write a yatzee game with C. And im stuck already and its the start?!?! I want the user to type there 5 numbers. i.e My program so far does this Please...
2
abehm
by: abehm | last post by:
Hey everyone, I'm trying to input a string as an xml data type into sql server, but i keep getting this error. Am I doing this incorrectly, or do i need to format the string? XmlDocument mydoc...
6
abehm
by: abehm | last post by:
Hey everyone, I'm trying to input a string as an xml data type into sql server, but i keep getting this error. Am I doing this incorrectly, or do i need to format the string? XmlDocument...
5
by: semomaniz | last post by:
The problem that i am having is when ever i input text in format like O'Neal as lastname then my code breaks and gives me following error Incorrect syntax near 'Neal'. Unclosed quotation mark...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.