C# error in invoke code

Hi,
I am getting this error while running this code in invoke code for C# as a language.
“error CS1022: Type or namespace definition, or end-of-file expected”

using System;
using System.Data;
using System.Data.SqlClient;

class Program
{
static void Main()
{
string connectionString = “Data Source=DESKTOP-TAEHG2M;Initial Catalog=AdventureWorks;Integrated Security=True”;

    DataTable dataTable = dsMarks.Tables(0);

    
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();

        // Step 1: Truncate the SQL Server table
        string truncateQuery = "TRUNCATE TABLE dbo.StudentMarks";
        
        using (SqlCommand command = new SqlCommand(truncateQuery, connection))
        {
            command.ExecuteNonQuery();
        }

        // Step 2: Insert data from the DataTable to the SQL Server table
        using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
        {
            bulkCopy.DestinationTableName = "StudentMarks";
            bulkCopy.WriteToServer(dataTable);
        }

        connection.Close();
    }
}

}

Can anyone please help.

anything you put inside invoke code, is run inside a function
So you cannot use “import” at the top
Those you need to add on the namespaces tab of the workflow

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.