Hi. I have never used a forum before. I hope that someone can help me. :)
I am using VWD 2008 Express edition to build an editable datagrid.
My problem is with the Update Function:
Sub dgShows_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
'Determine the value of the Customer ID Column
Dim ShowID As Integer = e.Item.Cells(1).Text
'Reference each TextBox
Dim dateTextBox As TextBox = e.Item.Cells(2).Controls(0)
Dim venueTextBox As TextBox = e.Item.Cells(3).Controls(0)
Dim timeTextBox As TextBox = e.Item.Cells(4).Controls(0)
Dim commentsTextBox As TextBox = e.Item.Cells(5).Controls(0)
UpdateShow(ShowID, venueTextBox.Text, timeTextBox.Text, dateTextBox.Text, commentsTextBox.Text)
dgShows.EditItemIndex = -1
dgShows.DataSource = GethbShows()
dgShows.DataBind()
End Sub
' Insert page code here
Function UpdateShow(ByVal ShowID As Integer, ByVal Venue As String, ByVal Time As String, ByVal [Date] As DateTime, ByVal Comments As String) As Integer
Dim connectionString As String = "my Cstring'"
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "UPDATE [Customers] SET [Venue]=@Venue, [Time]=@Phone, [Time]=@Time, [Date]=@Date, [Commments]=@Comments WHERE ([S" & _
"hows].[ShowID] = @ShowID)"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlCommand.Parameters.Add("@ShowID", System.Data.SqlDbType.Int).Value = ShowID
sqlCommand.Parameters.Add("@Venue", System.Data.SqlDbType.VarChar).Value = Venue
sqlCommand.Parameters.Add("@Time", System.Data.SqlDbType.VarChar).Value = Time
sqlCommand.Parameters.Add("@Date", System.Data.SqlDbType.DateTime).Value = [Date]
sqlCommand.Parameters.Add("@Coments", System.Data.SqlDbType.VarChar).Value = Comments
Dim rowsAffected As Integer = 0
sqlConnection.Open()
Try
rowsAffected = sqlCommand.ExecuteNonQuery
Finally
sqlConnection.Close()
End Try
Return rowsAffected
End Function
When I change the data in the grid and click on the update btn, I get:
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 error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
But the ShowID has been declared as an Int ???
I am new to this and very frustrated at the moment. Can someone help me please?
Thank you