ork/data/adonet/sqlclient-streaming-support) .

[ IOException ](system.io.ioexception?view=dotnet-plat-ext-8.0)

An error occurred in a [ Stream ](system.io.stream?view=dotnet-plat-ext-8.0) ,
[ XmlReader ](system.xml.xmlreader?view=dotnet-plat-ext-8.0) or [ TextReader
](system.io.textreader?view=dotnet-plat-ext-8.0) object during a streaming
operation. For more information about streaming, see [ SqlClient Streaming
Support ](/en-us/dotnet/framework/data/adonet/sqlclient-streaming-support) .

[ InvalidOperationException ](system.invalidoperationexception?view=dotnet-
plat-ext-8.0)

The [ SqlConnection ](system.data.sqlclient.sqlconnection?view=dotnet-plat-
ext-8.0) closed or dropped during a streaming operation. For more information
about streaming, see [ SqlClient Streaming Support ](/en-
us/dotnet/framework/data/adonet/sqlclient-streaming-support) .

[ ObjectDisposedException ](system.objectdisposedexception?view=dotnet-plat-
ext-8.0)

The [ Stream ](system.io.stream?view=dotnet-plat-ext-8.0) , [ XmlReader
](system.xml.xmlreader?view=dotnet-plat-ext-8.0) or [ TextReader
](system.io.textreader?view=dotnet-plat-ext-8.0) object was closed during a
streaming operation. For more information about streaming, see [ SqlClient
Streaming Support ](/en-us/dotnet/framework/data/adonet/sqlclient-streaming-
support) .

##  Examples

The following example creates a [ SqlCommand
](system.data.sqlclient.sqlcommand?view=dotnet-plat-ext-8.0) and then executes
it using [ ExecuteNonQuery
](system.data.sqlclient.sqlcommand.executenonquery?view=dotnet-plat-ext-8.0) .
The example is passed a string that is a Transact-SQL statement (such as
UPDATE, INSERT, or DELETE) and a string to use to connect to the data source.

    
    
    private static void CreateCommand(string queryString,
        string connectionString)
    {
        using (SqlConnection connection = new SqlConnection(
                   connectionString))
        {
            SqlCommand command = new SqlCommand(queryString, connection);
            command.Connection.Open();
            command.ExecuteNonQuery();
        }
    }
    
    
    
    Public Sub CreateCommand(ByVal queryString As String, _
      ByVal connectionString As String)
        Using connection As New SqlConnection(connectionString)
            Dim command As New SqlCommand(queryString, connection)
            command.Connection.Open()
            command.ExecuteNonQuery()
        End Using
    End Sub
    

##  Remarks

You can use the [ ExecuteNonQuery
](system.data.sqlclient.sqlcommand.executenonquery?view=dotnet-plat-ext-8.0)
to perform catalog operations (for example, querying the structure of a
database or creating database objects such as tables), or to change the data
in a database without using a [ DataSet ](system.data.dataset?view=dotnet-
plat-ext-8.0) by executing UPDATE, INSERT, or DELETE statements.

Although the [ ExecuteNonQuery
](system.data.sqlclient.sqlcommand.executenonquery?view=dotnet-plat-ext-8.0)
returns no rows, any output parameters or return values mapped to parameters
are populated with data.

For UPDATE, INSERT, and DELETE statements, the return value is the number of
rows affected by the command. For all other types of statements, the return
value is -1.

When a trigger exists on a table being inserted or updated, the return value
includes the number of rows affected by both the insert or update operation
and the number of rows affected by the trigger or triggers.

When SET NOCOUNT ON is set on the connection (before or as part of executing
the command, or as part of a trigger initiated by the execution of the
command) the rows affected by individual statements stop contributing to the
count of rows affected that is returned by this method.

If no statements are detected that contribute to the count, the return value
is -1. If a rollback occurs, the return value is also -1.

##  Applies to

##  See also

  * [ Retrieving and Modifying Data in ADO.NET ](/en-us/dotnet/framework/data/ad