Hi guys,

Can you help pls?

I have some code and I am having probs with it.

Trying to update a record in SQL Server 2k through the update command in a datagrid - with no success.

Here's my code. If anyone can help I will be really thankful.

-----------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim CurrentCategoryID As Long
Dim DBConn As SqlConnection
Dim DBCommand As SqlDataAdapter
Dim DSPageData As New DataSet()
DBConn = New SqlConnection("Server=localhost;" _
& "Initial Catalog=erhartdb;" _
& "Integrated Security=SSPI")
DBCommand = New SqlDataAdapter _
("Select RentID, Reference, Lease, Type, Location, " _
& "BriefDescription, NoBedrooms, Pool, Balcony, MonthlyRent " _
& "From RentEng Order By Reference", DBConn)
DBCommand.Fill(DSPageData, "Properties")
dgProducts.DataSource = _
DSPageData.Tables("Properties").DefaultView
dgProducts.DataKeyField = "Reference"
dgProducts.DataBind()

End Sub

Private Sub dgProducts_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgProducts.UpdateCommand
Dim DBConn As SqlConnection
Dim DBUpdate As New SqlCommand()
Dim DSPageData As New DataSet()
DBConn = New SqlConnection("Server=localhost;" _
& "Initial Catalog=erhartdb;" _
& "Integrated Security=SSPI")
Dim RefA, LeaseA, TypeA, LocationA As String
RefA = CType(e.Item.Cells(1).Controls(0), TextBox).Text
LeaseA = CType(e.Item.Cells(2).Controls(0), TextBox).Text
TypeA = CType(e.Item.Cells(3).Controls(0), TextBox).Text
LocationA = "Playa"
'LocationA = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Label1.Text = RefA
Label2.Text = LocationA

DBUpdate.CommandText = "Update RentEng SET Location = RefA"


DBUpdate.Connection = DBConn
DBUpdate.Connection.Open()
DBUpdate.ExecuteNonQuery()
DBUpdate.Connection.Close()


'Response.Redirect("./Amend.aspx")

End Sub

Private Sub dgProducts_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgProducts.CancelCommand
dgProducts.EditItemIndex = -1
DataBind()
End Sub

Private Sub dgProducts_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgProducts.EditCommand
dgProducts.EditItemIndex = e.Item.ItemIndex
DataBind()
End Sub


End Class


-----------------------------

Thanks if you can, and, well, thanks for trying if you can't.

Cheers,

BikerCaz