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
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