SoFunction
Updated on 2025-03-06

C# Code example sharing of c# tests the speed of native SQL computing

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection conn = new SqlConnection();
            SqlCommand comm = new SqlCommand();
            DateTime t1, t2;
int count = 10000;  //Number of loops
            string times;
            = "Data Source=.;Initial Catalog=Server;Integrated Security=True";
= "insert into test (Cid,Cvalue) values('1','1')"; //Data insertion
            = conn;
("Start insert data\r\nStart time:" +(t1=).ToLongTimeString());
            try
            {
                ();
                for (int i = 1; i <= count; i++)
                {
(); //Execute query
                }
("End Time:" + (t2 = ).ToLongTimeString());
                times = GetTimeSpan(t1, t2).ToString();
("Duration:" + (0, (".") + 4));
("This test performed a total of "count + "data insertion operations!");
                // = "delete from test";
                //();
//("Test data has been deleted");
            }
            catch (Exception err)
            {
                ();
            }
            finally
            {
                comm = null;
                ();
                ();
            }
            ();
        }