<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – 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>
    <description>Recent content in Loading data through 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/loading-data-through-ado-net/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Connecting-To: Using the OpenText Analytics Database data adapter</title>
      <link>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/loading-data-through-ado-net/using-data-adapter/</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/using-data-adapter/</guid>
      <description>
        
        
        &lt;p&gt;The OpenText™ Analytics Database data adapter (VerticaDataAdapter) enables a client to exchange data between a data set and a database. It is an implementation of DbDataAdapter. You can use VerticaDataAdapter to simply read data, or, for example, read data from a database into a data set and then write changed data from the data set back to the database.&lt;/p&gt;
&lt;h2 id=&#34;batching-updates&#34;&gt;Batching updates&lt;/h2&gt;
&lt;p&gt;When using the Update() method to update a dataset, you can optionally use the UpdateBatchSize() method prior to calling Update() to reduce the number of times the client communicates with the server to perform the update. The default value of UpdateBatchSize is 1. If you have multiple rows.Add() commands for a data set, then you can change the batch size to an optimal size to speed up the operations your client must perform to complete the update.&lt;/p&gt;
&lt;h2 id=&#34;reading-data-from-opentexttrade-analytics-database-using-the-data-adapter&#34;&gt;Reading data from OpenText™ Analytics Database using the data adapter&lt;/h2&gt;
&lt;p&gt;The following example details how to perform a select query on the VMart schema and load the result into a DataTable, then output the contents of the DataTable to the console.&lt;/p&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 System.Data.SqlClient;
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();

            // Try/Catch any exceptions
                   try
            {
                using (_conn)
                {
                    // Create the command
                    VerticaCommand command = _conn.CreateCommand();
                    command.CommandText = &amp;#34;select product_key, product_description &amp;#34; +
                        &amp;#34;from product_dimension where product_key &amp;lt; 10&amp;#34;;

                        // Associate the command with the connection
                        command.Connection = _conn;

                        // Create the DataAdapter
                        VerticaDataAdapter adapter = new VerticaDataAdapter();
                        adapter.SelectCommand = command;

                        // Fill the DataTable
                        DataTable table = new DataTable();
                        adapter.Fill(table);

                        //  Display each row and column value.
                        int i = 1;
                        foreach (DataRow row in table.Rows)
                        {
                            foreach (DataColumn column in table.Columns)
                            {
                                Console.Write(row[column] + &amp;#34;\t&amp;#34;);
                            }
                            Console.WriteLine();
                            i++;
                        }
                    Console.WriteLine(i + &amp;#34; rows returned.&amp;#34;);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            _conn.Close();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;reading-data-from-opentexttrade-analytics-database-into-a-data-set-and-changing-data&#34;&gt;Reading data from OpenText™ Analytics Database into a data set and changing data&lt;/h2&gt;
&lt;p&gt;The following example shows how to use a data adapter to read from and insert into a dimension table of the VMart schema.&lt;/p&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 System.Data.SqlClient;
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();

                  // Try/Catch any exceptions
                    try
            {
                using (_conn)
                {

                            //Create a data adapter object using the connection
                            VerticaDataAdapter da = new VerticaDataAdapter();

                            //Create a select statement that retrieves data from the table
                            da.SelectCommand = new
                        VerticaCommand(&amp;#34;select * from product_dimension where product_key &amp;lt; 10&amp;#34;,
                        _conn);
                            //Set up the insert command for the data adapter, and bind variables for some of the columns
                            da.InsertCommand = new
                        VerticaCommand(&amp;#34;insert into product_dimension values( :key, :version, :desc )&amp;#34;,
                        _conn);
                    da.InsertCommand.Parameters.Add(new VerticaParameter(&amp;#34;key&amp;#34;, VerticaType.BigInt));
                    da.InsertCommand.Parameters.Add(new VerticaParameter(&amp;#34;version&amp;#34;, VerticaType.BigInt));
                    da.InsertCommand.Parameters.Add(new VerticaParameter(&amp;#34;desc&amp;#34;, VerticaType.VarChar));
                    da.InsertCommand.Parameters[0].SourceColumn = &amp;#34;product_key&amp;#34;;
                    da.InsertCommand.Parameters[1].SourceColumn = &amp;#34;product_version&amp;#34;;
                    da.InsertCommand.Parameters[2].SourceColumn = &amp;#34;product_description&amp;#34;;
                    da.TableMappings.Add(&amp;#34;product_key&amp;#34;, &amp;#34;product_key&amp;#34;);
                    da.TableMappings.Add(&amp;#34;product_version&amp;#34;, &amp;#34;product_version&amp;#34;);
                    da.TableMappings.Add(&amp;#34;product_description&amp;#34;, &amp;#34;product_description&amp;#34;);

                            //Create and fill a Data set for this dimension table, and get the resulting DataTable.
                            DataSet ds = new DataSet();
                    da.Fill(ds, 0, 0, &amp;#34;product_dimension&amp;#34;);
                    DataTable dt = ds.Tables[0];

                            //Bind parameters and add two rows to the table.
                            DataRow dr = dt.NewRow();
                    dr[&amp;#34;product_key&amp;#34;] = 838929;
                    dr[&amp;#34;product_version&amp;#34;] = 5;
                    dr[&amp;#34;product_description&amp;#34;] = &amp;#34;New item 5&amp;#34;;
                    dt.Rows.Add(dr);
                    dr = dt.NewRow();
                    dr[&amp;#34;product_key&amp;#34;] = 838929;
                    dr[&amp;#34;product_version&amp;#34;] = 6;
                    dr[&amp;#34;product_description&amp;#34;] = &amp;#34;New item 6&amp;#34;;
                    dt.Rows.Add(dr);
                    //Extract the changes for the added rows.
                            DataSet ds2 = ds.GetChanges();

                            //Send the modifications to the server.
                            int updateCount = da.Update(ds2, &amp;#34;product_dimension&amp;#34;);

                           //Merge the changes into the original Data set, and mark it up to date.
                            ds.Merge(ds2);
                    ds.AcceptChanges();
                    Console.WriteLine(updateCount + &amp;#34; updates made!&amp;#34;);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            _conn.Close();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Connecting-To: Using batch inserts and prepared statements</title>
      <link>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/loading-data-through-ado-net/using-batch-inserts-and-prepared-statements/</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/using-batch-inserts-and-prepared-statements/</guid>
      <description>
        
        
        &lt;p&gt;You can load data in batches using a prepared statement with parameters. You can also use transactions to rollback the batch load if any errors are encountered.&lt;/p&gt;
&lt;p&gt;If you are loading large batches of data (more than 100MB), then consider using a direct batch insert.&lt;/p&gt;
&lt;p&gt;The following example details using data contained in arrays, parameters, and a transaction to batch load data.&lt;/p&gt;
&lt;p&gt;The &lt;span class=&#34;sql&#34;&gt;test&lt;/span&gt; table used in the example is created with the command:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE test (id INT, username VARCHAR(24), email VARCHAR(64), password VARCHAR(8));
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For information about overlong strings in this scenario, see the &lt;a href=&#34;../../../../../../../en/sql-reference/config-parameters/general-parameters/#AddEnforceLengthDuringCopyRewrite&#34;&gt;AddEnforceLengthDuringCopyRewrite&lt;/a&gt; configuration parameter.&lt;/p&gt;
&lt;h2 id=&#34;example-batch-insert-using-parameters-and-transactions&#34;&gt;Example batch insert using parameters and transactions&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();
            // Create arrays for column data
                    int[] ids = {1, 2, 3, 4};
            string[] usernames = {&amp;#34;user1&amp;#34;, &amp;#34;user2&amp;#34;, &amp;#34;user3&amp;#34;, &amp;#34;user4&amp;#34;};
            string[] emails = { &amp;#34;user1@example.com&amp;#34;, &amp;#34;user2@example.com&amp;#34;,&amp;#34;user3@example.com&amp;#34;,&amp;#34;user4@example.com&amp;#34; };
            string[] passwords = { &amp;#34;pass1&amp;#34;, &amp;#34;pass2&amp;#34;, &amp;#34;pass3&amp;#34;, &amp;#34;pass4&amp;#34; };
            // create counters for accepted and rejected rows
                    int rows = 0;
            int rejRows = 0;
            bool error = false;
            // Create the transaction
                    VerticaTransaction txn = _conn.BeginTransaction();
            // Create the parameterized query and assign parameter types
                    VerticaCommand command = _conn.CreateCommand();
            command.CommandText = &amp;#34;insert into TEST values (@id, @username, @email, @password)&amp;#34;;
            command.Parameters.Add(new VerticaParameter(&amp;#34;id&amp;#34;, VerticaType.BigInt));
            command.Parameters.Add(new VerticaParameter(&amp;#34;username&amp;#34;, VerticaType.VarChar));
            command.Parameters.Add(new VerticaParameter(&amp;#34;email&amp;#34;, VerticaType.VarChar));
            command.Parameters.Add(new VerticaParameter(&amp;#34;password&amp;#34;, VerticaType.VarChar));
            // Prepare the statement
                    command.Prepare();

                    // Loop through the column arrays and insert the data
                    for (int i = 0; i &amp;lt; ids.Length; i++)            {
                command.Parameters[&amp;#34;id&amp;#34;].Value = ids[i];
                command.Parameters[&amp;#34;username&amp;#34;].Value = usernames[i];
                command.Parameters[&amp;#34;email&amp;#34;].Value = emails[i];
                command.Parameters[&amp;#34;password&amp;#34;].Value = passwords[i];
                try
                {
                    rows += command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Console.WriteLine(&amp;#34;\nInsert failed - \n  &amp;#34; + e.Message + &amp;#34;\n&amp;#34;);
                    ++rejRows;
                    error = true;
                }
            }
            if (error)
            {
                // Roll back if errors
                        Console.WriteLine(&amp;#34;Errors. Rolling Back Transaction.&amp;#34;);
                Console.WriteLine(rejRows + &amp;#34; rows rejected.&amp;#34;);
                txn.Rollback();
            }
            else
            {
                // Commit if no errors
                        Console.WriteLine(&amp;#34;No Errors. Committing Transaction.&amp;#34;);
                txn.Commit();
                Console.WriteLine(&amp;#34;Inserted &amp;#34; + rows + &amp;#34; rows. &amp;#34;);
            }
            _conn.Close();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Connecting-To: Streaming data via ADO.NET</title>
      <link>/en/connecting-to/client-libraries/accessing/c/querying-db-using-ado-net/loading-data-through-ado-net/streaming-data-via-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/streaming-data-via-ado-net/</guid>
      <description>
        
        
        &lt;p&gt;There are two options to stream data from a file on the client to your OpenText™ Analytics Database through ADO.NET:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the &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/streaming-from-client-via-verticacopystream/&#34;&gt;&lt;code&gt;VerticaCopyStream&lt;/code&gt;&lt;/a&gt; ADO.NET class to stream data in an object-oriented manner&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Execute a &lt;a href=&#34;../../../../../../../en/sql-reference/statements/copy-local/#&#34;&gt;COPY LOCAL&lt;/a&gt; SQL statement to stream the data&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The topics in this section explain how to use these options.&lt;/p&gt;

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