<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Querying the database using ADO.NET</title>
    <link>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/</link>
    <description>Recent content in Querying the database using ADO.NET on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Connecting-To: Inserting data (ADO.NET)</title>
      <link>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/inserting-data-ado-net/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/inserting-data-ado-net/</guid>
      <description>
        
        
        &lt;p&gt;Inserting data can done using the VerticaCommand class. VerticaCommand is an implementation of DbCommand. It allows you to create and send a SQL statement to the database. Use the CommandText method to assign a SQL statement to the command and then execute the SQL by calling the ExecuteNonQuery method. The ExecuteNonQuery method is used for executing statements that do not return result sets.&lt;/p&gt;
&lt;h2 id=&#34;to-insert-a-single-row-of-data&#34;&gt;To insert a single row of data:&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../../../en/connecting-to/client-libraries/accessing/c/connecting-to-db/opening-and-closing-db-connection-ado-net/&#34;&gt;Create a connection to the database&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a command object using the connection.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;VerticaCommand command = _conn.CreateCommand();
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Insert data using an INSERT statement. The following is an example of a simple insert. Note that it does not contain a COMMIT statement because the ADO.NET driver operates in autocommit mode.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;command.CommandText =
     &amp;#34;INSERT into test values(2, &amp;#39;username&amp;#39;, &amp;#39;email&amp;#39;, &amp;#39;password&amp;#39;)&amp;#34;;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute the query. The rowsAdded variable contains the number of rows added by the insert statement.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Int32 rowsAdded = command.ExecuteNonQuery();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The ExecuteNonQuery() method returns the number of rows affected by the command for UPDATE, INSERT, and DELETE statements. For all other types of statements it returns -1. If a rollback occurs then it is also set to -1.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;example-usage&#34;&gt;Example usage:&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder();
            builder.Host = &amp;#34;192.168.1.10&amp;#34;;
            builder.Database = &amp;#34;VMart&amp;#34;;
            builder.User = &amp;#34;dbadmin&amp;#34;;
            VerticaConnection _conn = new VerticaConnection(builder.ToString());
            _conn.Open();
        VerticaCommand command = _conn.CreateCommand();
        command.CommandText =
               &amp;#34;INSERT into test values(2, &amp;#39;username&amp;#39;, &amp;#39;email&amp;#39;, &amp;#39;password&amp;#39;)&amp;#34;;
        Int32 rowsAdded = command.ExecuteNonQuery();
        Console.WriteLine( rowsAdded + &amp;#34; rows added!&amp;#34;);
            _conn.Close();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Connecting-To: Reading data (ADO.Net)</title>
      <link>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/reading-data-ado-net/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/reading-data-ado-net/</guid>
      <description>
        
        
        &lt;p&gt;To read data from the database use VerticaDataReader, an implementation of DbDataReader. This implementation is useful for moving large volumes of data quickly off the server where it can be run through analytic applications.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

A VerticaCommand cannot execute anything else while it has an open VerticaDataReader associated with it. To execute something else, close the data reader or use a different VerticaCommand object.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;to-read-data-from-the-database-using-verticadatareader&#34;&gt;To read data from the database using VerticaDataReader:&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../../../en/connecting-to/client-libraries/accessing/c/connecting-to-db/opening-and-closing-db-connection-ado-net/&#34;&gt;Create a connection to the database&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a command object using the connection.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;    VerticaCommand command = _conn.CreateCommand();
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a query. This query works with the example VMart database.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;        command.CommandText =
        &amp;#34;SELECT fat_content, product_description &amp;#34; +
        &amp;#34;FROM (SELECT DISTINCT fat_content, product_description&amp;#34; +
        &amp;#34;      FROM product_dimension &amp;#34; +
        &amp;#34;      WHERE department_description &amp;#34; +        &amp;#34;      IN (&amp;#39;Dairy&amp;#39;) &amp;#34; +
        &amp;#34;      ORDER BY fat_content) AS food &amp;#34; +
        &amp;#34;LIMIT 10;&amp;#34;;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute the reader to return the results from the query. The following command calls the ExecuteReader method of the VerticaCommand object to obtain the VerticaDataReader object.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;VerticaDataReader dr = command.ExecuteReader();
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Read the data. The data reader returns results in a sequential stream. Therefore, you must read data from tables row-by-row. The following example uses a while loop to accomplish this:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt; Console.WriteLine(&amp;#34;\n\n Fat Content\t  Product Description&amp;#34;);
     Console.WriteLine(&amp;#34;------------\t  -------------------&amp;#34;);
     int rows = 0;
     while (dr.Read())
     {
        Console.WriteLine(&amp;#34;     &amp;#34; + dr[0] + &amp;#34;    \t  &amp;#34; + dr[1]);
        ++rows;
     }
     Console.WriteLine(&amp;#34;------------\n  (&amp;#34; + rows + &amp;#34; rows)\n&amp;#34;);
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When you&#39;re finished, close the data reader to free up resources.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;    dr.Close();
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;example-usage&#34;&gt;Example usage:&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Vertica.Data.VerticaClient;
namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            VerticaConnectionStringBuilder builder = new VerticaConnectionStringBuilder();
            builder.Host = &amp;#34;192.168.1.10&amp;#34;;
            builder.Database = &amp;#34;VMart&amp;#34;;
            builder.User = &amp;#34;dbadmin&amp;#34;;
            VerticaConnection _conn = new VerticaConnection(builder.ToString());
            _conn.Open();
        VerticaCommand command = _conn.CreateCommand();
            command.CommandText =
                &amp;#34;SELECT fat_content, product_description &amp;#34; +
                &amp;#34;FROM (SELECT DISTINCT fat_content, product_description&amp;#34; +
                &amp;#34;      FROM product_dimension &amp;#34; +
                &amp;#34;      WHERE department_description &amp;#34; +
                &amp;#34;      IN (&amp;#39;Dairy&amp;#39;) &amp;#34; +
                &amp;#34;      ORDER BY fat_content) AS food &amp;#34; +
                &amp;#34;LIMIT 10;&amp;#34;;
          VerticaDataReader dr = command.ExecuteReader();

         Console.WriteLine(&amp;#34;\n\n Fat Content\t  Product Description&amp;#34;);
         Console.WriteLine(&amp;#34;------------\t  -------------------&amp;#34;);
         int rows = 0;
         while (dr.Read())
         {
                Console.WriteLine(&amp;#34;     &amp;#34; + dr[0] + &amp;#34;    \t  &amp;#34; + dr[1]);
                ++rows;
         }
         Console.WriteLine(&amp;#34;------------\n  (&amp;#34; + rows + &amp;#34; rows)\n&amp;#34;);
              dr.Close();
            _conn.Close();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Connecting-To: Loading data through ADO.Net</title>
      <link>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/loading-data-through-ado-net/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/loading-data-through-ado-net/</guid>
      <description>
        
        
        &lt;p&gt;This section details the different ways that you can load data in OpenText™ Analytics Database using the ADO.NET client driver:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../../../../en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/loading-data-through-ado-net/using-data-adapter/&#34;&gt;Using the OpenText™ Analytics Database Data Adapter&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../../../en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/loading-data-through-ado-net/using-batch-inserts-and-prepared-statements/#&#34;&gt;Using batch inserts and prepared statements&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../../../en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/loading-data-through-ado-net/streaming-data-via-ado-net/#&#34;&gt;Streaming data via ADO.NET&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
  </channel>
</rss>
