c0deM0nK424
Programmer
First off, to give u an idea as to what my implementation looks like, view this screenshot link below.
I'm bamboozled as to why updates arent performed. Insert and Delete work fine.
The whole thing is implemented using the repeater control, and i've cleverly assigned command name buttons to appear as well. If I'm not mistaken, once upon a 'few moments in 2008' I 'did something' which was making UPDATE work fine !
THEN thinking i'd resolved the issue, i tried to get ahead of myself and started playing around with the code by adding checkboxes int the repeater (dont ask why I do strange things sometimes...) and when i tried to undo one too many changes, i was back to square one. No update happening. :|
WHAT have i done/not done ?
The actual sub routine thats fired when the update command button is clicked is as follows:
<script runat="server">
Sub Update_Record(ByVal Src As Object, ByVal Args As RepeaterCommandEventArgs)
' subroutine that is called by onItemCommand, i.e when the submit buttons are clicked.
Dim Stock_ID As TextBox = Args.Item.FindControl("Stock_ID")
Dim Stock_Name As TextBox = Args.Item.FindControl("Stock_Name")
Dim Quantity As TextBox = Args.Item.FindControl("Quantity")
Dim Price As TextBox = Args.Item.FindControl("Price")
If Args.CommandName = "Insert" Then
' if the button happened to be insert
' then
Dim myquery As String = "INSERT INTO Stock_details (Stock_Name , Quantity, Price) VALUES ('" & Stock_Name.Text & "', '" & Quantity.Text & "', '" & Price.Text & "')"
' assign the following insert query to 'myquery
StockInfo.InsertCommand = myquery
StockInfo.Insert()
Response.Redirect("Default.aspx")
' End If
ElseIf Args.CommandName = "Update" Then
' If Args.CommandName = "Update" Then
' Dim myquery As String = "UPDATE Stock_details SET " & _
' "Stock_Name = '" & Stock_Name.Text & "', " & _
' "Quantity = '" & Quantity.Text & "', " & _
' "Price = '" & Price.Text & "', " & _
' "WHERE Stock_ID = '" & Stock_ID.Text & "'"
Dim myquery As String = "UPDATE Stock_details SET & Stock_Name = '" & Stock_Name.Text & "', & Quantity = '" & Quantity.Text & "', & Price = '" & Price.Text & "', WHERE Stock_ID = '" & Stock_ID.Text & "'"
StockInfo.UpdateCommand = myquery
StockInfo.Update()
Response.Redirect("Default.aspx")
' End If
ElseIf Args.CommandName = "Delete" Then
' If Args.CommandName = "Delete" Then
Dim myquery As String = "DELETE FROM Stock_details WHERE Stock_ID = " & Stock_ID.Text
StockInfo.DeleteCommand = myquery
StockInfo.Delete()
Response.Redirect("Default.aspx")
End If
End Sub
</script>
I commented out some of the end if's and replaced them with else if's, both do the job but it doesnt change anything, update button causes an error heh.
does the update query look okay to you guys ??
I'm bamboozled as to why updates arent performed. Insert and Delete work fine.
The whole thing is implemented using the repeater control, and i've cleverly assigned command name buttons to appear as well. If I'm not mistaken, once upon a 'few moments in 2008' I 'did something' which was making UPDATE work fine !
THEN thinking i'd resolved the issue, i tried to get ahead of myself and started playing around with the code by adding checkboxes int the repeater (dont ask why I do strange things sometimes...) and when i tried to undo one too many changes, i was back to square one. No update happening. :|
WHAT have i done/not done ?
The actual sub routine thats fired when the update command button is clicked is as follows:
<script runat="server">
Sub Update_Record(ByVal Src As Object, ByVal Args As RepeaterCommandEventArgs)
' subroutine that is called by onItemCommand, i.e when the submit buttons are clicked.
Dim Stock_ID As TextBox = Args.Item.FindControl("Stock_ID")
Dim Stock_Name As TextBox = Args.Item.FindControl("Stock_Name")
Dim Quantity As TextBox = Args.Item.FindControl("Quantity")
Dim Price As TextBox = Args.Item.FindControl("Price")
If Args.CommandName = "Insert" Then
' if the button happened to be insert
' then
Dim myquery As String = "INSERT INTO Stock_details (Stock_Name , Quantity, Price) VALUES ('" & Stock_Name.Text & "', '" & Quantity.Text & "', '" & Price.Text & "')"
' assign the following insert query to 'myquery
StockInfo.InsertCommand = myquery
StockInfo.Insert()
Response.Redirect("Default.aspx")
' End If
ElseIf Args.CommandName = "Update" Then
' If Args.CommandName = "Update" Then
' Dim myquery As String = "UPDATE Stock_details SET " & _
' "Stock_Name = '" & Stock_Name.Text & "', " & _
' "Quantity = '" & Quantity.Text & "', " & _
' "Price = '" & Price.Text & "', " & _
' "WHERE Stock_ID = '" & Stock_ID.Text & "'"
Dim myquery As String = "UPDATE Stock_details SET & Stock_Name = '" & Stock_Name.Text & "', & Quantity = '" & Quantity.Text & "', & Price = '" & Price.Text & "', WHERE Stock_ID = '" & Stock_ID.Text & "'"
StockInfo.UpdateCommand = myquery
StockInfo.Update()
Response.Redirect("Default.aspx")
' End If
ElseIf Args.CommandName = "Delete" Then
' If Args.CommandName = "Delete" Then
Dim myquery As String = "DELETE FROM Stock_details WHERE Stock_ID = " & Stock_ID.Text
StockInfo.DeleteCommand = myquery
StockInfo.Delete()
Response.Redirect("Default.aspx")
End If
End Sub
</script>
I commented out some of the end if's and replaced them with else if's, both do the job but it doesnt change anything, update button causes an error heh.
does the update query look okay to you guys ??