Recent Posts

ASP.NET: Thực thi truy vấn UPDATE 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 UpdateCommand As SqlCommand = New SqlCommand()
UpdateCommand.Connection = conn
Dim sql As String = "Update categories Set categoryName = @CatName WHERE CategoryID = @CatID"

UpdateCommand.CommandText = sql

UpdateCommand.Parameters.Add("@CatName", SqlDbType.NVarChar, 250).Value = "Category Name"
UpdateCommand.Parameters.Add("@CatID", SqlDbType.Int).Value = 14
Try
conn.Open()
UpdateCommand.ExecuteNonQuery()
Catch ex As Exception
response.Write(ex.ToString())
Finally
conn.Close()
End Try
end sub
</script>




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