Hi,
I have 2 table and 1 column in each one like this;
------------------------------------------------------------------
Column1 Column2
1 3
2 4
3 5
4 6
... ...
------------------------------------------------------------------
I want to compare column1's values with column2, and get the values which arent exist in column2. For example in this instance, I want to get "1" and "2" values.
Obversely, when I compare column2's values with column1, I want to get only these values; "5" and "6"
I tryed datatable, datareader and lots of codes but I didnt get the logic. How can I do that?
Regards.
Loading
Satyapriya NayakPosted Sep 11, 2011, 12:09 PM
Here is your solution
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
Default2.aspx.cs code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from t1 except select * from t2";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from t2 except select * from t1";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
con.Close();
}
}
Thanks
If this post helps you mark it as answer
VulpesPosted Sep 11, 2011, 9:18 AM