1550387897
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:
connection.Open(); 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(); sd.Fill(dt1); 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(); secondDA.Fill(dtForSecond); foreach (DataRow mySecondRow in dtForSecond.Rows) { dgv2.Rows.Add(mySecondRow["c1"].ToString() + " " + mySecondRow["c2"].ToString(), mySecondRow["c3"]); } } con.Close();
Note 1: I edited my code.
Note 2: Please share your full answer. Thank you so much.
#c-sharp #sql-server #database
1550453230
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.
GO
;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
GO
You’ll get your desired result from that query only for above given table structure.
If any confusion then ping me for same.
1595201363
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,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
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.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = [
'name','description'
];
}
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.
routes/web.php
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
1624240146
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. Vim, Sublime 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++
1597937354
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:
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.
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.
#problems-with-c #dicey-issues-in-c #c-programming #c++ #c #cplusplus
1589805240
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
1589816580
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#