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

Người đăng: share-nhungdieuhay on Thứ Ba, 30 tháng 4, 2013


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

{ 0 nhận xét... read them below or add one }

Đăng nhận xét