web 2.0

VB.NET & ExecuteNonQuery()

VB.NET & ExecuteNonQuery() The ExecuteNonQuery executes a Transact-SQL statement against the connection and returns the number of rows affected.

ShotDev Focus:
- VB.NET & ExecuteNonQuery()

Example

ExecuteNonQuery.aspx

 <%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">

Dim objConn As System.Data.OleDb.OleDbConnection
Dim objCmd As System.Data.OleDb.OleDbCommand
Dim strConnString,strSQL As String

strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;"
objConn = New System.Data.OleDb.OleDbConnection(strConnString)
objConn.Open()

strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
"VALUES ('C005','Weerachai Nukitram','webmaster@shotdev.com','TH','2000000','1000000')"

objCmd = New System.Data.OleDb.OleDbCommand(strSQL,objConn)

Try
objCmd.ExecuteNonQuery()
Catch ex As Exception
lblText.Text = "Record Cannot Insert : Error (" & ex.Message & ")"
End Try

objCmd = Nothing
objConn.Close()
objConn = Nothing

</script>

.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.