vb.net qr code dll CommandNonQuery: Module1.vb in VB.NET

Drawing Data Matrix ECC200 in VB.NET CommandNonQuery: Module1.vb

Listing 6-4. CommandNonQuery: Module1.vb
Data Matrix 2d Barcode Generation In Visual Basic .NET
Using Barcode generation for .NET framework Control to generate, create Data Matrix 2d barcode image in VS .NET applications.
www.OnBarcode.com
Reading DataMatrix In VB.NET
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Imports System Imports System.Data Imports System.Data.SqlClient Module Module1 Sub Main() ' Set up connection string Dim connString As String = _ "server = .\sqlexpress;" _ & "integrated security = true;" _ & "database = northwind" ' Set up query Dim sqlqry As String = _ "select " _ & " count(*) " _ & "from " _ & " employees"
Generating Code 3 Of 9 In Visual Basic .NET
Using Barcode drawer for VS .NET Control to generate, create Code 39 Extended image in .NET framework applications.
www.OnBarcode.com
Barcode Generator In VB.NET
Using Barcode encoder for .NET framework Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
' Set up insert statement Dim sqlins As String = _ "insert into employees " _ & "( " _ & " firstname, " _ & " lastname " _
Painting Barcode In VB.NET
Using Barcode printer for .NET framework Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Draw Matrix In Visual Basic .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create Matrix Barcode image in .NET framework applications.
www.OnBarcode.com
CHAPTER 6 s INTRODUCING COMMANDS
QR Code ISO/IEC18004 Drawer In VB.NET
Using Barcode creator for .NET Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications.
www.OnBarcode.com
International Standard Book Number Generator In Visual Basic .NET
Using Barcode creator for .NET Control to generate, create ISBN - 13 image in Visual Studio .NET applications.
www.OnBarcode.com
& ") " _ & "values('Zachariah', 'Zinn')" ' Set up delete statement Dim sqldel As String = _ "delete from employees " _ & "where " _ & " firstname = 'Zachariah' " _ & " and " _ & " lastname = 'Zinn' " ' Create connection Dim conn As SqlConnection = New SqlConnection(connString) ' Create commands Dim cmdqry as SqlCommand = new SqlCommand(sqlqry, conn) Dim cmdnon as SqlCommand = new SqlCommand(sqlins, conn) Console.WriteLine("Command created and connected.") Try ' Open connection conn.Open() ' Execute query to get number of employees Console.WriteLine( _ "Before INSERT: Number of employees = " & cmdqry.ExecuteScalar()) ' Execute nonquery to insert an employee Console.WriteLine( _ "Executing statement " & cmdnon.CommandText) cmdnon.ExecuteNonQuery() Console.WriteLine( _ "After INSERT: Number of employees = " & cmdqry.ExecuteScalar()) ' Execute nonquery to delete an employee cmdnon.CommandText = sqldel Console.WriteLine( _ "Executing statement " & cmdnon.CommandText) cmdnon.ExecuteNonQuery() Console.WriteLine( _ "After DELETE: Number of employees = " & cmdqry.ExecuteScalar()) Catch e As Exception
Data Matrix Drawer In Objective-C
Using Barcode printer for iPhone Control to generate, create Data Matrix ECC200 image in iPhone applications.
www.OnBarcode.com
ECC200 Creation In Java
Using Barcode creation for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
www.OnBarcode.com
CHAPTER 6 s INTRODUCING COMMANDS
Code 3 Of 9 Recognizer In .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Scanning Code-39 In C#.NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
' Display error Console.WriteLine("Error: " & e.ToString) Finally ' Close connection conn.Close() End Try End Sub End Module
Barcode Decoder In Java
Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications.
www.OnBarcode.com
Decoding Data Matrix In VB.NET
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
3. Make it the startup project, and then run it with Ctrl+F5. You should see the result in Figure 6-6.
Barcode Encoder In None
Using Barcode printer for Online Control to generate, create Barcode image in Online applications.
www.OnBarcode.com
Print Code-128 In None
Using Barcode creator for Excel Control to generate, create Code-128 image in Microsoft Excel applications.
www.OnBarcode.com
Figure 6-6. Executing statements
UPC-A Supplement 5 Drawer In Visual Studio .NET
Using Barcode printer for Reporting Service Control to generate, create UPC-A Supplement 5 image in Reporting Service applications.
www.OnBarcode.com
UCC - 12 Recognizer In Visual Studio .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
How It Works
Reading Barcode In Visual Studio .NET
Using Barcode Control SDK for ASP.NET Control to generate, create, read, scan barcode image in ASP.NET applications.
www.OnBarcode.com
Barcode Encoder In None
Using Barcode drawer for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
In this program you used a scalar query and two statements, storing the SQL in three string variables:
' Set up query Dim sqlqry As String = _ "select " _ & " count(*) " _ & "from " _ & " employees" ' Set up insert statement Dim sqlins As String = _ "insert into employees " _ & "( " _ & " firstname, " _ & " lastname " _ & ") " _ & "values('Zachariah', 'Zinn')"
CHAPTER 6 s INTRODUCING COMMANDS
' Set up delete statement Dim sqldel As String = _ "delete from employees " _ & "where " _ & " firstname = 'Zachariah' " _ & " and " _ & " lastname = 'Zinn' "
Then you created two commands. The first was cmdqry, which encapsulates the scalar query to count the rows in the Employees table. You used this command several times to monitor the number of rows as you inserted and deleted employees. The second was cmdnon, which you used twice, first to insert a row and then to delete the same row. You initially set its CommandText to the INSERT statement SQL
Dim cmdnon as SqlCommand = new SqlCommand(sqlins, conn)
and later reset it to the DELETE statement SQL
cmdnon.CommandText = sqldel;
executing the SQL statements with two calls to
cmdnon.CommandText = sqldel ExecuteNonQuery() returns an Integer indicating how many rows were affected by the
command. Since you want to display the number of affected rows, you put the call to
ExecuteNonQuery() within a call to Console.WriteLine(). You used ExecuteScalar() to display the number of rows, before and after the INSERT and DELETE operations. Console.WriteLine( _ "After INSERT: Number of employees = " & cmdqry.ExecuteScalar())
Note that both cmdqry and cmdnon are SqlCommand objects. The difference between submitting queries and statements is the method you use to submit them.
s Note With ExecuteNonQuery() you can submit virtually any SQL statement, including Data Definition
Language (DDL) statements to create and drop database objects like tables and indexes. We ll create tables in 10 using SSMSE, because that s how they re typically created, but the SQL you learn there can be submitted from a VB program with ExecuteNonQuery().
Copyright © OnBarcode.com . All rights reserved.