---
sidebar_position: 10
description: Add rows and other functions to work with MSSQL in the Open Integration Package, a free open-source integration library for 1C:Enterprise 8, OneScript and CLI
keywords: [1C, 1С, 1С:Enterprise, 1С:Enterprise 8.3, API, Integration, Services, Exchange, OneScript, CLI, MSSQL]
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Add rows
 Adds new rows to the table



`Function AddRecords(Val Table, Val DataArray, Val Transaction = True, Val Connection = "", Val Tls = "") Export`

  | Parameter | CLI option | Type | Required | Description |
  |-|-|-|-|-|
  | Table | --table | String | &#x2714; | Table name |
  | DataArray | --rows | Array of Structure | &#x2714; | An array of string data structures: Key > field, Value > field value |
  | Transaction | --trn | Boolean | &#x2716; | True > adding records to transactions with rollback on error |
  | Connection | --dbc | String, Arbitrary | &#x2716; | Connection or connection string |
  | Tls | --tls | Structure Of KeyAndValue | &#x2716; | TLS settings, if necessary. See GetTlsSettings |

  
  Returns:  Map Of KeyAndValue - Result of query execution

:::tip
Record data is specified as an array of structures of the following type:<br/>`{'Field name 1': {'Type': 'Value'}, 'Field name 2': {'Type': 'Value'},...}`

List of available types is described on the initial page of the MSSQL library documentation
:::
<br/>


```bsl title="1C:Enterprise/OneScript code example"
    Address  = "127.0.0.1";
    Login    = "SA";
    Password = "12we...";
    Base     = "testbase1";

    TLSSettings      = OPI_MSSQL.GetTLSSettings(True);
    ConnectionString = OPI_MSSQL.GenerateConnectionString(Address, Base, Login, Password);

    Table        = "testtable";
    RecordsArray = New Array;

    Image = "https://hut.openintegrations.dev/test_data/picture.jpg";
    OPI_TypeConversion.GetBinaryData(Image); // Image - Type: BinaryData

    XML = "<?xml version=""1.0""?><root>
        | <element>
        | <name>Example</name>
        | <value>123</value>
        | </element>
        | <element>
        | <name>Test</name>
        | <value>456</value>
        | </element>
        |</root>";

    CurrentDate   = OPI_Tools.GetCurrentDate();
    CurrentDateTZ = OPI_Tools.DateRFC3339(CurrentDate, "+05:00");

    RecordStructure = New Structure;
    RecordStructure.Insert("tinyint_field"  , New Structure("TINYINT"       , 5));
    RecordStructure.Insert("smallint_field" , New Structure("SMALLINT"      , 2000));
    RecordStructure.Insert("int_field"      , New Structure("INT"           , 200000));
    RecordStructure.Insert("bigint_field"   , New Structure("BIGINT"        , 20000000000));
    RecordStructure.Insert("float24_field"  , New Structure("FLOAT24"       , 10.1234567));
    RecordStructure.Insert("float53_field"  , New Structure("FLOAT53"       , 10.123456789123456));
    RecordStructure.Insert("bit_field"      , New Structure("BIT"           , True));
    RecordStructure.Insert("nvarchar_field" , New Structure("NVARCHAR"      , "Some text"));
    RecordStructure.Insert("varbinary_field", New Structure("BYTES"         , Image));
    RecordStructure.Insert("uid_field"      , New Structure("UUID"          , New UUID));
    RecordStructure.Insert("numeric_field"  , New Structure("NUMERIC"       , 5.333));
    RecordStructure.Insert("xml_field"      , New Structure("XML"           , XML));
    RecordStructure.Insert("date_field"     , New Structure("DATE"          , CurrentDate));
    RecordStructure.Insert("time_field"     , New Structure("TIME"          , CurrentDate));
    RecordStructure.Insert("dto_field"      , New Structure("DATETIMEOFFSET", CurrentDateTZ));
    RecordStructure.Insert("datetime_field" , New Structure("DATETIME"      , CurrentDate));

    RecordsArray.Add(RecordStructure);

    // When using the connection string, a new connection is initialised,
    // which will be closed after the function is executed.
    // If several operations are performed, it is desirable to use one connection,
    // previously created by the CreateConnection function()
    Result = OPI_MSSQL.AddRecords(Table, RecordsArray, True, ConnectionString, TLSSettings);
```
 

 <Tabs>
  
    <TabItem value="bash" label="Bash" default>
        ```bash
            # JSON data can also be passed as a path to a .json file
            
            oint mssql AddRecords \
             --table "testtable" \
             --rows "[{'tinyint_field':{'TINYINT':5},'smallint_field':{'SMALLINT':2000},'int_field':{'INT':200000},'bigint_field':{'BIGINT':20000000000},'float24_field':{'FLOAT24':10.1234567},'float53_field':{'FLOAT53':10.123456789123456},'bit_field':{'BIT':true},'nvarchar_field':{'NVARCHAR':'Some text'},'varbinary_field':{'BYTES':'/tmp/nkaryw0f.02v'},'uid_field':{'UUID':'27484a05-348b-4a5a-b0d1-b41ffca60ca8'},'numeric_field':{'NUMERIC':5.333},'xml_field':{'XML':'<?xml version=\"'"1.0\"'"?><root>  <element>  <name>Example</name>  <value>123</value>  </element>  <element>  <name>Test</name>  <value>456</value>  </element> </root>'},'date_field':{'DATE':'2025-12-10T19:17:51.5315716Z'},'time_field':{'TIME':'2025-12-10T19:17:51.5315716Z'},'dto_field':{'DATETIMEOFFSET':'2025-12-10T19:17:51.5315716+05:00'},'datetime_field':{'DATETIME':'2025-12-10T19:17:51.5315716Z'}}]" \
             --trn true \
             --dbc "Server=127.0.0.1;Database=***;User Id=SA;Password=***;" \
             --tls "{'use_tls':true,'accept_invalid_certs':true}"
        ```
    </TabItem>
  
    <TabItem value="bat" label="CMD/Bat" default>
        ```batch
            :: JSON data can also be passed as a path to a .json file
            
            oint mssql AddRecords ^
             --table "testtable" ^
             --rows "[{'tinyint_field':{'TINYINT':5},'smallint_field':{'SMALLINT':2000},'int_field':{'INT':200000},'bigint_field':{'BIGINT':20000000000},'float24_field':{'FLOAT24':10.1234567},'float53_field':{'FLOAT53':10.123456789123456},'bit_field':{'BIT':true},'nvarchar_field':{'NVARCHAR':'Some text'},'varbinary_field':{'BYTES':'/tmp/nkaryw0f.02v'},'uid_field':{'UUID':'27484a05-348b-4a5a-b0d1-b41ffca60ca8'},'numeric_field':{'NUMERIC':5.333},'xml_field':{'XML':'<?xml version=\"'"1.0\"'"?><root>  <element>  <name>Example</name>  <value>123</value>  </element>  <element>  <name>Test</name>  <value>456</value>  </element> </root>'},'date_field':{'DATE':'2025-12-10T19:17:51.5315716Z'},'time_field':{'TIME':'2025-12-10T19:17:51.5315716Z'},'dto_field':{'DATETIMEOFFSET':'2025-12-10T19:17:51.5315716+05:00'},'datetime_field':{'DATETIME':'2025-12-10T19:17:51.5315716Z'}}]" ^
             --trn true ^
             --dbc "Server=127.0.0.1;Database=***;User Id=SA;Password=***;" ^
             --tls "{'use_tls':true,'accept_invalid_certs':true}"
        ```
    </TabItem>
</Tabs>


```json title="Result"
{
 "commit": {
  "result": true
 },
 "result": true,
 "rows": 1,
 "errors": []
}
```
