"Fossies" - the Fresh Open Source Software Archive

Member "sqlrelay-1.5.2/doc/programming/parts/ado.net-execute.cs" (23 Apr 2019, 1108 Bytes) of package /linux/privat/sqlrelay-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "ado.net-execute.cs": 1.2.0_vs_1.3.0.

    1 using System;
    2 using SQLRClient;
    3 using System.Data;
    4 using System.IO;
    5 
    6 namespace SQLRExamples
    7 {
    8     class SQLRExample
    9     {
   10         public static void Main()
   11         {
   12             SQLRelayConnection sqlrcon = new SQLRelayConnection("Data Source=sqlrserver:9000;User ID=user;Password=password;Retry Time=0;Tries=1;Debug=false");
   13             sqlrcon.Open();
   14 
   15 
   16             // DML queries...
   17             SQLRelayCommand sqlrcom = (SQLRelayComand)sqlrcon.CreateCommand();
   18             sqlrcom.CommandText = "insert into exampletable values (1,'hello')";
   19             try
   20             {
   21                 sqlrcom.ExecuteNonQuery();
   22             }
   23             catch (Exception ex)
   24             {
   25                 ... handle exceptions ...
   26             }
   27 
   28 
   29             // Single values
   30             sqlrcom.CommandText = "select 1 from dual";
   31             try
   32             {
   33                 Int64 value = sqlrcom.ExecuteScalar();
   34 
   35                 ... do something with the value ...
   36             }
   37             catch (Exception ex)
   38             {
   39                 ... handle exceptions ...
   40             }
   41 
   42 
   43             // Multiple rows
   44             sqlrcom.CommandText = "select * from exampletable";
   45             try
   46             {
   47                 System.Data.IDataReader datareader = sqlrcom.ExecuteReader();
   48 
   49                 ... do something with the result set ...
   50             }
   51             catch (Exception ex)
   52             {
   53                 ... handle exceptions ...
   54             }
   55         }
   56     }
   57 }