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

G

Guest

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).FindControl("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
 
T

Tod Birdsall

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top