Debbie Clay

Debbie Clay


Comparing Of Two DataGridView And Delete Same Rows In C#

I have 2 DataGridViews. After doing some operations in my first DataGridView, I transfer the rows ??to my second DataGridView. Now, I want to do this. In my second DataGridView, I don't want to add rows that are the same as the first DataGridView.

My DataGridView1 looks like that:

           Column 1                Column 2
           hello friends              250
           hi guys                    15
           good day                   15684
           old days                   156153
           bye bye                    6143

If my DataGridView2 looks like that;

           Column 1                Column 2
           new coders                 88
           hello friends              250
           january february           31
           such good                  1684
           play music                 1553
           bye bye                    6143

I don't want to see same rows in my DataGridView2 (from DataGridView1) and I don't want to add it. So my DataGridView2 should look like that;

           Column 1                Column 2
           new coders                 88
           january february           31
           such good                  1684
           play music                 1553

It's my code:

       string[] ss = listBox.SelectedItem.ToString().Split(' ');
       int css = ss.Count();
       for (int mi = 0; mi < css; mi++)
           string mq = "SELECT c1, c2, c3 FROM myTable WHERE c1='" + ss[mi] + "' OR c2='" + ss[mi] + "'";
           SqlDataAdapter da = new SqlDataAdapter(mq, connection);
           DataTable dt1 = new DataTable();
           foreach (DataRow r in dt1.Rows)
               dgv1.Rows.Add(r["c1"].ToString() + " " + r["c2"].ToString(), r["c3"]);
       //Some insignificant operations.
       for (int mi2 = 0; mi2 < countOFMYNEWFORDGV1; mi2++)
           string mySecondQuery= "SELECT c1, c2, c3 FROM myTable WHERE c1='" + myNEWFORDGV1[mi2] + "' OR c2='" + myNEWFORDGV1[mi2] + "'";
           SqlDataAdapter secondDA= new SqlDataAdapter(mySecondQuery, conection);
           DataTable dtForSecond= new DataTable();
           foreach (DataRow mySecondRow in dtForSecond.Rows)
               dgv2.Rows.Add(mySecondRow["c1"].ToString() + " " + mySecondRow["c2"].ToString(), mySecondRow["c3"]);                        

Note 1: I edited my code.

Note 2: Please share your full answer. Thank you so much.

#c-sharp #sql-server #database

What is GEEK

Buddha Community

Watts Kendall


Instead of looping through each row I would suggest to get the result in single query. By using left outer join we’ll get all the results of DataGridView2 with common record of DataGridView1, then we’ll filter out the required record by filter of null values.


  ;with cte as (
    Select dg2.[Column 1] as c1, dg2.[Column 2] as c2, dg1.[Column 1] as dc1 
    from DataGridView2 as dg2 left outer join DataGridView1 as dg1 
    on dg2.[Column 1]=dg1.[Column 1] and dg2.[Column 2]=dg1.[Column 2] )
  select * from cte where dc1 is null


You’ll get your desired result from that query only for above given table structure.

If any confusion then ping me for same.

Seamus  Quitzon

Seamus Quitzon


Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.


namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
    protected $fillable = [

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.


Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

Tamale  Moses

Tamale Moses


How to Run C/C++ in Sublime Text?

C and C++ are the most powerful programming language in the world. Most of the super fast and complex libraries and algorithms are written in C or C++. Most powerful Kernel programs are also written in C. So, there is no way to skip it.

In programming competitions, most programmers prefer to write code in C or C++. Tourist is considered the worlds top programming contestant of all ages who write code in C++.

During programming competitions, programmers prefer to use a lightweight editor to focus on coding and algorithm designing. VimSublime Text, and Notepad++ are the most common editors for us. Apart from the competition, many software developers and professionals love to use Sublime Text just because of its flexibility.

I have discussed the steps we need to complete in this blog post before running a C/C++ code in Sublime Text. We will take the inputs from an input file and print outputs to an output file without using freopen file related functions in C/C++.

#cpp #c #c-programming #sublimetext #c++ #c/c++

Dicey Issues in C/C++

If you are familiar with C/C++then you must have come across some unusual things and if you haven’t, then you are about to. The below codes are checked twice before adding, so feel free to share this article with your friends. The following displays some of the issues:

  1. Using multiple variables in the print function
  2. Comparing Signed integer with unsigned integer
  3. Putting a semicolon at the end of the loop statement
  4. C preprocessor doesn’t need a semicolon
  5. Size of the string matters
  6. Macros and equations aren’t good friends
  7. Never compare Floating data type with double data type
  8. Arrays have a boundary
  9. Character constants are different from string literals
  10. Difference between single(=) and double(==) equal signs.

The below code generates no error since a print function can take any number of inputs but creates a mismatch with the variables. The print function is used to display characters, strings, integers, float, octal, and hexadecimal values onto the output screen. The format specifier is used to display the value of a variable.

  1. %d indicates Integer Format Specifier
  2. %f indicates Float Format Specifier
  3. %c indicates Character Format Specifier
  4. %s indicates String Format Specifier
  5. %u indicates Unsigned Integer Format Specifier
  6. %ld indicates Long Int Format Specifier

Image for post

A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a non-negative integer in the range [0 to 4294967295]. The signed integer is represented in twos-complement notation. In the below code the signed integer will be converted to the maximum unsigned integer then compared with the unsigned integer.

Image for post

#problems-with-c #dicey-issues-in-c #c-programming #c++ #c #cplusplus

Sadie  Ratke

Sadie Ratke


How to Use String compare() in C++?

Hey, folks! In this article, we will be focusing on the working of C++ string compare() function along with its variants.

#c++ #c #c# #programming-c

Ari  Bogisich

Ari Bogisich


Using isdigit() in C/C++

In this article, we’ll take a look at using the isdigit() function in C/C++. This is a very simple way to check if any value is a digit or not. Let’s look at how to use this function, using some simple examples.

#c programming #c++ #c #c#