Input string incorrect format

  • Thread starter Thread starter Big E
  • Start date Start date
B

Big E

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.ConnectionString")

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").Value =
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
 
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top