10/03/2011

'Delete Data' (MS SQL SERVER, ASP.NET,VB Script)

Berikut di sertakan contoh koding untuk memadam data menggunakan ASP.NET ( VB Script) pada database MS SQL Server. Bila pengguna klik pada button delete data 2, senarai record dalam database akan di paparkan dan di sebelahnya di letakkan satu link kepada fail deleteuser.aspx
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)

'Display Data' & 'Add Data' (MS SQL , ASP.NET)



No comments:

Cara download Installer windows 10 dalam format ISO

1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan.  ...