Recent Posts

ASP.NET: Thực thi truy vấn DELETE sử dụng đối tượng SQLCommand

-

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>

<script language="VB" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)

Dim conn As New SQLConnection("server=LOCALHOST;User id='sa';password='123';database=Northwind")
Dim DeleteCommand As SqlCommand = New SqlCommand()
DeleteCommand.Connection = conn
Dim sql As String = "Delete from categories  WHERE CategoryID = @CatID"

DeleteCommand.CommandText = sql

DeleteCommand.Parameters.Add("@CatID", SqlDbType.Int).Value = 14
Try
conn.Open()
DeleteCommand.ExecuteNonQuery()
Catch ex As Exception
response.Write(ex.ToString())
Finally
conn.Close()
End Try

End sub




Klik untuk melihat kode: :) =( :s :D :-D ^:D ^o^ 7:( :Q :p T_T @@, :-a :W *fck* x@