Groups | Blog | Home
all groups > asp.net webcontrols > october 2003 >

asp.net webcontrols : editablegrid


TJS
10/14/2003 12:56:35 PM
I am stumped on an editablegrid error

msde
webmatrix

one table (orders) two fields (orderID,custname)

error on update command text in following subroutine
any suggestions ????

============================================

Sub DataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)
' update the database with the new values
' get the edit text boxes

Dim OrderID As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
'<== error on this line
Dim custName As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text

' TODO: update the Command value for your application
Dim myConnection As New SqlConnection(ConnectionString)
Dim UpdateCommand As SqlCommand = new SqlCommand()

UpdateCommand.Connection = myConnection

If AddingNew = True Then
UpdateCommand.CommandText = "INSERT INTO orders(custName) VALUES (
@custName )"
Else
UpdateCommand.CommandText = "UPDATE [orders] set [CustName]=@CustName
WHERE ([orders].[OrderID] = @OrderID)"
End If

UpdateCommand.Parameters.Add("@custName", SqlDbType.VarChar, 200).Value =
custName

' execute the command
Try
myConnection.Open()
UpdateCommand.ExecuteNonQuery()
Catch ex as Exception
Message.Text = ex.ToString()
Finally
myConnection.Close()
End Try


' Resort the grid for new records
If AddingNew = True Then
DataGrid1.CurrentPageIndex = 0
AddingNew = false
End If
' rebind the grid
DataGrid1.EditItemIndex = -1
BindGrid()
End Sub

chak
10/17/2003 11:20:01 PM
I think the value of the cell should be stored in a variable of type
TextBox, not String.

Also, is your Ctype missing it's second parameter ?


[quoted text, click to view]

AddThis Social Bookmark Button