<%@ 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>
<%@ 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>
0 Response to ASP.NET: Thực thi truy vấn INSERT sử dụng đối tượng SQLCommand
Post a Comment