2013년 4월 27일 토요일
ASP.NET: Thực thi truy vấn INSERT sử dụng đối tượng SQLCommand
Posted By:
Unknown
on 오후 4:41
<%@ 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 InsertCommand As SqlCommand = New SqlCommand()
InsertCommand.Connection = conn
Dim sql As String = "INSERT INTO categories (categoryName) VALUES (@newCatName)"
InsertCommand.CommandText = sql
InsertCommand.Parameters.Add("@newCatName", SqlDbType.NVarChar, 250).Value = "Category Name"
Try
conn.Open()
InsertCommand.ExecuteNonQuery()
Catch ex As Exception
response.Write(ex.ToString())
Finally
conn.Close()
End Try
end sub
</script>
피드 구독하기:
댓글 (Atom)
0 개의 댓글:
댓글 쓰기