By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

one page to edit, delete, and add data to a database

P: n/a
I am creating one page to edit, delete, and add data to a database. The Add
code works but the Edit and Delete do not. What am I doing wrong? If you need
more code let me know.
Thanks
Code:
Sub Submit(Source as Object, E as EventArgs)

Select Case strCommand
Case "Add"
'Create the appropriate SQL statement
Dim intServerId = Request.QueryString("id")
Dim strSQL As String = "INSERT INTO tblRackInfo (ServerId,Application)
VALUES ( @ServerID,@Application)"
Dim MyConn as New SQLConnection(strConn)
Dim Cmd as New SQLCommand(strSQL, MyConn)
cmd.Parameters.Add(New SQLParameter("@Serverid", intServerId))
cmd.Parameters.Add(New SQLParameter("@Application", txtApp.text))
MyConn.Open()
cmd.ExecuteNonQuery
MyConn.Close()
Case "Delete"

'Dim chk as CheckBox = CType(itm.FindControl("chkRemove"), CheckBox)
' Dim lblID as Label =
rptDelApps.Items(e.Item.ItemIndex).cells(1).FindCo ntrol("lblID")
For Each MyItem As RepeaterItem In rptDelApps.Items
If MyItem.ItemType = ListItemType.Item Or MyItem.ItemType =
ListItemType.AlternatingItem Then
For Each MyControl As Control In MyItem.Controls
If TypeOf (MyControl) Is System.Web.UI.WebControls.CheckBox Then
If CType(MyControl, CheckBox).Checked = True Then
' Dim lblID as Label = MyItem.FindControl("lblID")
Dim DeleteCmd As String = "DELETE from tblRackInfo Where id ='" &
Request.QueryString("id") & "'"
Dim MyConn as New SQLConnection(strConn)
Dim Cmd as New SQLCommand(DeleteCmd, MyConn)
'Cmd.Parameters.Add(New SqlParameter("@ID", lblID.Text))
MyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
End If
End If
Next
End If
Next
rptDelApps.DataBind()

Case "Edit"
Dim MyConn as New SQLConnection(strConn)
Dim Cmd as New SQLCommand(strSQL, MyConn)
Dim intServerId = Request.QueryString("id")
strSQl ="UPDATE tblTPServers SET Name =@Name, Type =@Type, OS =@OS, CPU
=@CPU, RAM =@RAM, IP=@IP WHERE id='" & intServerId & "'"
MyConn = New SqlConnection(strConn)
Cmd = New SqlCommand(strSql, MyConn)

Cmd.Parameters.Add(New SQLParameter("@Name",txtServer.Text))
Cmd.Parameters.Add(New SQLParameter("@Type", txtServerType.text))
Cmd.Parameters.Add(New SQLParameter("@OS", txtOS.text))
Cmd.Parameters.Add(New SQLParameter("@CPU", txtCPU.text))
Cmd.Parameters.Add(New SQLParameter("@RAM", txtRAM.text))
Cmd.Parameters.Add(New SQLParameter("@IP", txtIP.text))
MyConn.Open()
cmd.ExecuteNonQuery
MyConn.Close()

End Select
End Sub
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Have you tried setting a breakpoint at "Cmd.ExecuteNonQuery()" line to
see if when you choose to delete, it gets to that line?

If you are getting to that line and it executes without any errors,
double check that the "DeleteCmd" string is correct.
Hope this helps.

Tod Birdsall
http://tod1d.blogspot.com

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.