Login | Register  

Executing Transact-SQL INSERT statement using SQLCommand

by Scud   Saturday, November 26, 2005 Rating:
 Vote this news:


 

Following example displays us how to send a query using an SQLCommand. We execute a simple Transact-SQL INSERT statement to show all rows from database. I have used Nowthwind sample database for this sample. 

 

<%@ 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 cnn As New SQLConnection("server=LOCALHOST;User id=SA;password=;database=Northwind")
Dim InsertCommand As SqlCommand = New SqlCommand()
InsertCommand.Connection = cnn
Dim sql As String
sql = "INSERT INTO categories (categoryName) VALUES (@newCatName)"

InsertCommand.CommandText = sql

InsertCommand.Parameters.Add("@newCatName", SqlDbType.NVarChar, 250).Value = "Category Name"

Try
cnn.Open()
InsertCommand.ExecuteNonQuery()
Catch ex As Exception
response.Write(ex.ToString())
Finally
cnn.Close()
End Try
end sub
</script>





Dotnetindex.com is listed with 411asp.net
Dotnetindex.com is listed with aspin.com
Dotnetindex.com is listed with jspin.com
PHP, ASP, .NET, JSP Resources, Reviews







page counter
Copyright © 2007 Powered by GNews Publisher Positive. All rights reserved. Contact Us - Load Time: 0.28 second(s)