Koding pada buttton Delete Data 2 adalah seperti berikut:-
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim ds As New DataSet ' yang ni kena ada Imports System.Data
Dim i As Integer
connetionString = "Server =4MEI-PC\MEMO; Database =dbmemo; Trusted_Connection =True;"
connection = New SqlConnection(connetionString)
Try
connection.Open()
adapter = New SqlDataAdapter("Select * from users", connection)
adapter.Fill(ds)
connection.Close()
For i = 0 To ds.Tables(0).Rows.Count - 1
Response.Write(ds.Tables(0).Rows(i).Item(1) & " ")
Response.Write(ds.Tables(0).Rows(i).Item(2))
Response.Write("delete")
Response.Write("
")
Next
Catch ex As Exception
Response.Write(ex.ToString)
End Try
Berikut adalah koding pada fail deleteuser.aspx
<%
Dim userid As String
Response.Write("deleteuser.aspx
")
userid = (Request.QueryString("userid"))
padam(userid)
%>
procedure padam adalah seperti berikut
Public Sub padam(ByVal userid As String)
' jgn lupa letak
'Imports System.Data.SqlClient
'Imports System.Data
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As New SqlDataAdapter
Dim sql As String
Response.Write("daripada function padam userid = " & userid)
connetionString = "Server =4MEI-PC\MEMO; Database =dbmemo; Trusted_Connection =True;"
connection = New SqlConnection(connetionString)
sql = "delete users where id ='" & userid & "'"
Try
connection.Open()
adapter.DeleteCommand = connection.CreateCommand
adapter.DeleteCommand.CommandText = sql
adapter.DeleteCommand.ExecuteNonQuery()
MsgBox("Record deleted !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Related Post(s)
No comments:
Post a Comment