468,544 Members | 1,810 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

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

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
1 1726
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.

Similar topics

10 posts views Thread by Jim | last post: by
11 posts views Thread by Steve Hoyer | last post: by
7 posts views Thread by seanmatthewwalsh | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.