Executing Transact SQL UPDATE statement using SQLCommand
Following example displays us how to send a query using an SQLCommand. We execute a simple Transact-SQL UPDATE 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 UpdateCommand As SqlCommand = New SqlCommand()
UpdateCommand.Connection = cnn
Dim sql As String
sql = "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
cnn.Open()
UpdateCommand.ExecuteNonQuery()
Catch ex As Exception
response.Write(ex.ToString())
Finally
cnn.Close()
End Try
end sub
</script>
- How to Refresh a web page or redirect to another page
- Custom Paging in ASP Fast And Easy
- Professional Contact Form
- Creating Access Database Connection String
- Using DateDiff function in SQL Statement
- Custom Paging results in ASPNET using A Better Way
- Sending Emails in JSP
- MySQL AB Offers its Enterprise Database Subscriptions through the New Red Hat Exchange
- Display Top N records from MS Access
- How to display date time in real time
- JSP Hit Counter Free Open Code
- ASP Ikon Ad Manager UPDATED
- Exporting Data From mySQL to Excel
- Generating XML files from SQL Database
- Delete Folders Online in ASP
- Easy Download Manager Free Version
- ASP Chat Box
- Writing Form Data to Text Files
- Paging Records in JSP
- What is Ecommerce and the Importance of Ecommerce
- Beginning-Ajax-and-ASPNET-35
- How to upload images to mySQL within PHP
- Simple XML RSS Parser
- Counting records in PHP mySQL
- ActiveNews Manager Freeware News Exchange Software
- How to write and use a JavaBean My frst java bean
- Paging Results in PHP
- Free User Registration Form
- A-timesaver-control-GridView
- ASPNET Web Counter Free Open Source Code
- Easy Download Manager Free Version
- ASP Chat Box
- Writing Form Data to Text Files
- Paging Records in JSP
- Beginning-Ajax-and-ASPNET-35
- How to upload images to mySQL within PHP
- Simple XML RSS Parser
- ActiveNews Manager Freeware News Exchange Software
- Counting records in PHP mySQL
- How to write and use a JavaBean My frst java bean
- Paging Results in PHP
- Free User Registration Form
- A-timesaver-control-GridView
- ASPNET Web Counter Free Open Source Code
- Comparing Dates