public void PerformSqlTask(int TaskNumber, MultithreadedInMemoryTableInsertMain ParentForm)
        {
            try
            {
                using (var con = new SqlConnection(ConnectionStringTextBox.Text))
                {
                    con.Open();

                    using (var cmd = con.CreateCommand())
                    {
                        if (OnDiskRadioButton.Checked)
                        {
                            cmd.CommandText = "EXEC OnDisk.InsertVehicleLocation @RegistrationNumber, @TrackedWhen, @Longitude, @Latitude;";
                        }
                        else
                        {
                            cmd.CommandText = "EXEC InMemory.InsertVehicleLocation @RegistrationNumber, @TrackedWhen, @Longitude, @Latitude;";
                        }
                        cmd.Parameters.Add(new SqlParameter("@RegistrationNumber", SqlDbType.NVarChar, 20));
                        cmd.Parameters.Add(new SqlParameter("@TrackedWhen", SqlDbType.DateTime2));
                        var p = new SqlParameter("@Longitude", SqlDbType.Decimal);
                        p.Precision = 18;
                        p.Scale = 4;
                        cmd.Parameters.Add(p);
                        p = new SqlParameter("@Latitude", SqlDbType.Decimal);
                        p.Precision = 18;
                        p.Scale = 4;
                        cmd.Parameters.Add(p);

                        var rnd = new Random();

                        var tran = con.BeginTransaction();
                        cmd.Transaction = tran;

                        for (int counter = 0; counter < NumberOfRowsPerThreadNumericUpDown.Value; counter++)
                        {
                            cmd.Parameters["@RegistrationNumber"].Value = "EA24-GL";
                            cmd.Parameters["@TrackedWhen"].Value = DateTime.Now;
                            cmd.Parameters["@Longitude"].Value = rnd.Next(100);
                            cmd.Parameters["@Latitude"].Value = rnd.Next(100);
                            cmd.ExecuteNonQuery();
                        }

                        tran.Commit();
                    }
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                ParentForm.errorHasOccurred = true;
                ParentForm.errorDetails = ex.ToString();
            }
        }
Пример #2
0
        public void PerformSqlTask(int TaskNumber, MultithreadedInMemoryTableInsertMain ParentForm)
        {
            try
            {
                using (var con = new SqlConnection(ConnectionStringTextBox.Text))
                {
                    con.Open();

                    using (var cmd = con.CreateCommand())
                    {
                        if (OnDiskRadioButton.Checked)
                        {
                            cmd.CommandText = "EXEC OnDisk.InsertVehicleLocation @RegistrationNumber, @TrackedWhen, @Longitude, @Latitude;";
                        }
                        else
                        {
                            cmd.CommandText = "EXEC InMemory.InsertVehicleLocation @RegistrationNumber, @TrackedWhen, @Longitude, @Latitude;";
                        }
                        cmd.Parameters.Add(new SqlParameter("@RegistrationNumber", SqlDbType.NVarChar, 20));
                        cmd.Parameters.Add(new SqlParameter("@TrackedWhen", SqlDbType.DateTime2));
                        var p = new SqlParameter("@Longitude", SqlDbType.Decimal);
                        p.Precision = 18;
                        p.Scale     = 4;
                        cmd.Parameters.Add(p);
                        p           = new SqlParameter("@Latitude", SqlDbType.Decimal);
                        p.Precision = 18;
                        p.Scale     = 4;
                        cmd.Parameters.Add(p);

                        var rnd = new Random();

                        var tran = con.BeginTransaction();
                        cmd.Transaction = tran;

                        for (int counter = 0; counter < NumberOfRowsPerThreadNumericUpDown.Value; counter++)
                        {
                            cmd.Parameters["@RegistrationNumber"].Value = "EA24-GL";
                            cmd.Parameters["@TrackedWhen"].Value        = DateTime.Now;
                            cmd.Parameters["@Longitude"].Value          = rnd.Next(100);
                            cmd.Parameters["@Latitude"].Value           = rnd.Next(100);
                            cmd.ExecuteNonQuery();
                        }

                        tran.Commit();
                    }
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                ParentForm.errorHasOccurred = true;
                ParentForm.errorDetails     = ex.ToString();
            }
        }