web 2.0

VB.NET & System.Data.SqlClient - ExecuteNonQuery()

VB.NET & System.Data.SqlClient - ExecuteNonQuery() - How to learn Connector/NET ADO.NET component  System.Data.SqlClient namespace is the .NET Framework Data Provider for SQL Server data source, Using the ExecuteNonQuery method for Executes a Transact-SQL statement  (Insert/Update/Delete) data  and returns the number of rows affected. (SQL Server 2000,2005,2008 Database)

ShotDev Focus:
- VB.NET & System.Data.SqlClient - ExecuteNonQuery()

Example

ExecuteNonQuery.aspx

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

Sub Page_Load(sender As Object, e As EventArgs)
Sample1()
'Sample2()
End Sub

Sub Sample1()

Dim objConn As System.Data.SqlClient.SqlConnection
Dim objCmd As System.Data.SqlClient.SqlCommand
Dim strConnString,strSQL As String

strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
objConn = New System.Data.SqlClient.SqlConnection(strConnString)
objConn.Open()

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

objCmd = New System.Data.SqlClient.SqlCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
objCmd.ExecuteNonQuery()

lblText.Text = "Record Insert Sucessful."

objCmd = Nothing
objConn.Close()
objConn = Nothing

End Sub

Sub Sample2()

Dim objConn As System.Data.SqlClient.SqlConnection
Dim objCmd As System.Data.SqlClient.SqlCommand
Dim strConnString,strSQL As String

strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
objConn = New System.Data.SqlClient.SqlConnection(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.SqlClient.SqlCommand(strSQL,objConn)

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

objCmd = Nothing
objConn.Close()
objConn = Nothing

End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="Server"></asp:Label>
</form>
</body>
</html>

Screenshot

VB.NET & System.Data.SqlClient - ExecuteNonQuery()
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

One Response to “VB.NET & System.Data.SqlClient - ExecuteNonQuery()”

  1. 2ministry…

Leave a Reply

You must be logged in to post a comment.