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.