Result set is not displaying in GridView - asp.net

When I type the information in the TextBox there is no result in the GridView only the URL Parameter appear.
For example.
FNameTextBox.Text = "Mark"
The result is nothing just the URL says that
http://localhost:65319/Example.aspx?FirstName=Mark
In the GridView there is no result.
This is my current code:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
Dim dt As New DataTable
Using con As New OdbcConnection("DRIVER={SQL Server};Server=WJNJPHR8TCX8P\SQLEXPRESS;Database=Fabrics;Integrated Security=True;"),
cmd As New OdbcCommand("SELECT * FROM [Client] WHERE [ClientId] = ? OR [FirstName] = ? OR [MiddleName] = ? OR [LastName] = ?", con)
con.Open()
If IsNumeric(idTextBox.Text) Then
cmd.Parameters.Add("#ClientId", OdbcType.Int).Value = Integer.Parse(idTextBox.Text)
Response.Redirect("Example.aspx?ClientId=" + idTextBox.Text)
Else
cmd.Parameters.Add("#ClientId", OdbcType.Int).Value = -1
End If
cmd.Parameters.Add("#FirstName", OdbcType.NVarChar).Value = FNameTextBox.Text
Response.Redirect("Example.aspx?FirstName=" + FNameTextBox.Text)
cmd.Parameters.Add("#MiddleName", OdbcType.NVarChar).Value = MNameTextBox.Text
Response.Redirect("Example.aspx?MiddleName=" + MNameTextBox.Text)
cmd.Parameters.Add("#LastName", OdbcType.NVarChar).Value = LNameTextBox.Text
Response.Redirect("Example.aspx?LastName=" + LNameTextBox.Text)
dt.Load(cmd.ExecuteReader())
End Using
GridView1.DataSourceID = Nothing
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Question:
How can I display the Result set in GridView?

Why using Response.Redirect? comment all of them and your code is working.

If you want to send first name, middle name, last name as a query string, you should firstly store all the values then redirect to another page, or send all the textbox values in single query string.
String fname = fNameTextBox.Text
String mname = mNameTextBox.Text
String lname = lNameTextBox.Text
Response.Redirect("Example.aspx?FirstName="+fname+"&MName="+mname+"&LastName=" + lname)
or
Response.Redirect("Example.aspx?FirstName="+fNameTextBox.text+"&MName="+mNameTextBox.text+"&LastName=" + lNameTextBox.text)

Related

Binding Url to Gridview

I want to bind the url to GridView but I don't know how.
For example when I type the http://localhost:12345/example.aspx?FirstName=John in the url it will give me the result in GridView that shows only with the FirstName "John".
Here's my curent code:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim dt As New DataTable
' Stablish ODBC Connection
Dim con As New OdbcConnection("DRIVER={SQL Server};Server=WJNJPHR8TCX8P\SQLEXPRESS;Database=Fabrics;Integrated Security=True;")
' Query Command
Dim cmd As New OdbcCommand("SELECT * FROM [Client] WHERE [FirstName] = ?", con)
con.Open()
' Gets the path (Example.aspx)
Dim path As String = HttpContext.Current.Request.Url.AbsolutePath
' Gets the host (localhost)
Dim host As String = HttpContext.Current.Request.Url.Host
' Gets the whole url (localhost:24124/Example.aspx)
Dim url As String = HttpContext.Current.Request.Url.AbsoluteUri
' Parse the query string variables into a NameValueCollection
Dim qscoll As NameValueCollection = HttpUtility.ParseQueryString(url)
' Iterate through the collection and shows the result in MsgBox
Dim sb As New StringBuilder()
For Each s As String In qscoll.AllKeys
sb.Append(s & " = " & qscoll(s) & vbCrLf)
Next s
MsgBox(sb.ToString)
' Gets all keys and values in query string and shows it on MsgBox
For Each key As String In HttpContext.Current.Request.QueryString.AllKeys
MsgBox("Key: " + key + " Value: " + Request.QueryString(key))
Next key
Dim FName As String = Request.QueryString("FirstName")
Dim par1 As New OdbcParameter
par1.OdbcType = OdbcType.NVarChar
par1.Value = FName
par1.ParameterName = "#FirtName"
cmd.Parameters.Add(par1)
'Shows the result in Data Grid
dt.Load(cmd.ExecuteReader()) '==> Error: Invalid use of default parameter
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Any help will do!
You can access your query string directly with
Dim firstName as string = Request.QueryString("firstName")
Then you must pass it as a parameter of the query before executing it
Dim par1 As New OdbcParameter
par1.DbType = DbType.String
par1.Value = firstName
par1.ParameterName = "#FirstName"
cmd.Parameters(1) = par1
Hope it helps
Answered my question!
Here's my code:
For Each key As String In HttpContext.Current.Request.QueryString.AllKeys
Dim FName As String = Request.QueryString("FirstName")
Dim par1 As New OdbcParameter With {
.OdbcType = OdbcType.NVarChar,
.Value = FName,
.ParameterName = "#FirstName"
}
cmd.Parameters.Add(par1)
MsgBox("Key: " + key + " Value: " + Request.QueryString(key))
dt.Load(cmd.ExecuteReader())
GridView1.DataSource = dt
GridView1.DataBind()
Next key
#isol Thanks for your help! :)

Error: An exception of type 'System.Data.SqlClient.SqlException' occured in System.Data.dll but was not handled in user code

I'm new to ASP.NET and building a little dynamic website for a salesdepartment to registere their sales for salescompetions.
I have a page, after one is logged in, that consists of a couple of comboboxes/dropdowns and at the buttom a 'SUBMIT' button which I want to trigger a new record in the database with all the selected data. everything seems to go fine for a second but eventually the following error message appears:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Invalid column name 'KunderID'.
Invalid column name 'KundeTypeID'.
Invalid column name 'MachineModellID'.
Invalid column name 'AntallID'.
Invalid column name 'BrukerID'.
It points to the following part (The line starting with MBExec =) in the DBConnection.vb file:
Public Shared Function MBExec(ByVal SQL As String) As String
Dim cmd As New SqlCommand(SQL, MBConn)
MBExec = Convert.ToString(cmd.ExecuteScalar())
cmd.Connection.Close()
End Function
On the sourcecode og the relevant page the relevant part of it is the following (bottom line starting with MBExec) whereby I cannot see that the columnsnames are wrong:
Protected Sub RegisterSale(sender As Object, e As EventArgs)
Dim KundeNavn As DropDownList = DropDownListKundeNavn
Dim TypeKunde As DropDownList = DropDownListTypeKunde
Dim MachineModell As DropDownList = DropDownListMachineModell
Dim Antall As DropDownList = DropDownListAntall
Dim Bruker As DropDownList = DropDownListBruker
If KundeNavn.SelectedItem.Text = "Velg" Then
Dim msg = "Select or add a new customer"
Dim msgTittle = "Missing Customer Name"
MsgBox(msg, MsgBoxStyle.Critical, msgTittle)
Exit Sub
Else
Dim msg1 = "Are you sure to continue?"
Dim title = "Confirm Sale Registration"
Dim style = MsgBoxStyle.YesNo
Dim responce = MsgBox(msg1, style, title)
If responce = MsgBoxResult.Yes Then
Dim msg = "Thank you for your efforts, you are closer to becoming a sales champion!"
Dim msgTittle = "Your Sale has been recorded"
MsgBox(msg, MsgBoxStyle.Information, msgTittle)
'Varibles to hold the DataValueField from the dropboxes
Dim KundeID As Integer
Dim TypeKundeID As Integer
Dim MachineModellID As Integer
Dim AntallID As Integer
Dim BrukerID As Integer
'Converts the DataValueField to an Integer
KundeID = Convert.ToInt32(KundeNavn.SelectedValue.ToString())
TypeKundeID = Convert.ToInt32(TypeKunde.SelectedValue.ToString())
MachineModellID = Convert.ToInt32(MachineModell.SelectedValue.ToString())
AntallID = Convert.ToInt32(Antall.SelectedValue.ToString())
BrukerID = Convert.ToInt32(Bruker.SelectedValue.ToString())
MBExec("INSERT INTO KyoceraSalgReg(KunderID, KundeTypeID, MachineModellID, AntallID, BrukerID) Values (KunderID, KundeTypeID, MachineModellID, AntallID, BrukerID)")
Exit Sub
Else
Exit Sub
End If
End If
End Sub
I would very much appreciate if anybody could help me in the right direction here. If I understand it correctly, somehow the column names are not recognized and I just don't see why.
Cheers:)
Update 1:
MBExec looks like this:
Public Shared Function MBExec(ByVal SQL As String) As String
Dim cmd As New SqlCommand(SQL, MBConn)
MBExec = Convert.ToString(cmd.ExecuteScalar())
cmd.Connection.Close()
End Function
And KunderID datatype is string, selection made from a DropDownList
Try this approach:
MBExec("INSERT INTO KyoceraSalgReg(KunderID, KundeTypeID, MachineModellID, AntallID, BrukerID) Values (#KunderID, #KundeTypeID, #MachineModellID, #AntallID, #BrukerID)")
Use parameterized query to add the values:
cmd.Parameter.AddWithValue("#KunderID", KunderID)
AddWithValue
You may need to make separate instances of the SqlParameter - Example
Protected Sub RegisterSale(sender As Object, e As EventArgs)
Dim KundeNavn As DropDownList = DropDownListKundeNavn
Dim TypeKunde As DropDownList = DropDownListTypeKunde
Dim MachineModell As DropDownList = DropDownListMachineModell
Dim Antall As DropDownList = DropDownListAntall
Dim Bruker As DropDownList = DropDownListBruker
'Varibles to hold the DataValueField from the dropboxes
Dim KunderID As Integer = Convert.ToInt32(KundeNavn.SelectedValue.ToString())
Dim TypeKundeID As Integer = Convert.ToInt32(TypeKunde.SelectedValue.ToString())
Dim MachineModellID As Integer = Convert.ToInt32(MachineModell.SelectedValue.ToString())
Dim AntallID As Integer = Convert.ToInt32(Antall.SelectedValue.ToString())
Dim BrukerID As Integer = Convert.ToInt32(Bruker.SelectedValue.ToString())
'Sets the Selected values from dropdownlist
Dim ParamKunderID = New SqlParameter()
ParamKunderID.ParameterName = "#KunderID"
ParamKunderID.Value = KunderID
Dim ParamTypeID = New SqlParameter
ParamTypeID.ParameterName = "#KundeTypeID"
ParamTypeID.Value = TypeKundeID
Dim ParamMachineModellID = New SqlParameter()
ParamMachineModellID.ParameterName = "#MachineModellID"
ParamMachineModellID.Value = MachineModellID
Dim ParamAntallID = New SqlParameter
ParamAntallID.ParameterName = "#AntallID"
ParamAntallID.Value = AntallID
Dim ParamBrukerID = New SqlParameter
ParamBrukerID.ParameterName = "#BrukerID"
ParamBrukerID.Value = BrukerID
If KundeNavn.SelectedItem.Text = "Velg" Then
Dim msg = "Velg eller legge til en ny kunde"
Dim msgTittle = "Mangler Kundenavn"
MsgBox(msg, MsgBoxStyle.Critical, msgTittle)
Exit Sub
Else
Dim msg1 = "Er du sikker på at du vil fortsette?"
Dim title = "Bekrefte salg registrering"
Dim style = MsgBoxStyle.YesNo
Dim responce = MsgBox(msg1, style, title)
If responce = MsgBoxResult.Yes Then
MBExec("INSERT INTO KyoceraSalgReg(KunderID, KundeTypeID, MachineModellID, AntallID, BrukerID)" & " Values " & "(" & KunderID & "," & TypeKundeID & "," & MachineModellID & "," & AntallID & "," & BrukerID & ")")
Dim msg = "Takk for din innsats, du er nærmere å bli et Salg Mester!"
Dim msgtittle = "Din salget er registrert"
MsgBox(msg, MsgBoxStyle.Information, msgtittle)
End If
End If
End Sub

gridview PageIndexChanging issue

I am trying to to loop through a dataset's value through the rows in a gridview and color in the text if that row matches.
The code below works however whenever I change the page through the PageIndexChanging and this function is ran again, the coloring doesn't work anymore. It still loops through the gridview if there is a match but the effects are not shown.
--variable initialization class instantiation--
--code to connect to db here--
mySQLCommand.CommandText = "SELECT ..."
mySQLAdapter = New SqlDataAdapter(mySQLCommand)
mySQLAdapter.Fill(myDataset)
Me.MainPageGridView.DataSource = myDataset
Me.MainPageGridView.DataBind()
mySQLCommand.CommandText = "SELECT ... The ID's to be matched"
mySQLAdapter = New SqlDataAdapter(mySQLCommand)
mySQLAdapter.Fill(myDatasetNew)
Me.MainPageGridView.DataSource = myDatasetNew
For Each dataRow In myDataset.Tables(0).Rows
thisID = dataRow("ID").ToString
For Each gvRow In Me.MainPageGridView.Rows
If gvRow.Cells(2).Text = thisID Then
For column = 0 To 14 Step 1
gvRow.Cells(column).ForeColor = Drawing.Color.RosyBrown
Next
Exit For
End If
Next
Next
Why don't you use MainPageGridView_RowDataBound event to match the id? I have re-factored your original code to something like below, please check and let me know if it works:
'In DataBind or some other method
'Load(myDataSet)
mySQLCommand.CommandText = "SELECT ..."
mySQLAdapter = New SqlDataAdapter(mySQLCommand)
mySQLAdapter.Fill(myDataset)
'Load myDatasetNew and bind it to grid
mySQLCommand.CommandText = "SELECT ... The ID's to be matched"
mySQLAdapter = New SqlDataAdapter(mySQLCommand)
mySQLAdapter.Fill(myDatasetNew)
Me.MainPageGridView.DataSource = myDatasetNew
Me.MainPageGridView.DataBind()
and perform id matching in
Protected Sub MainPageGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles MainPageGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim id As String = DataBinder.Eval(e.Row.DataItem, "ID") 'The name of ID column in "myDatasetNew"
Dim dv As System.Data.DataView = myDataset.Tables(0).DefaultView
dv.RowFilter = "ID = " & id
If dv.Count > 0 Then 'id matches
'Change foreclor of entire row
e.Row.ForeColor = Drawing.Color.RosyBrown
End If
End If
End Sub
You really need to do your data comparison in the GridView.RowDataBound event.

Dynamic tables with hyperlinks

I want to build a table based on data in a recordset with a hyperlink that calls a method which takes the message id from the link and redirects to another page to view the message. I've tried HTMLAnchors, LinkButtons but none seem to work.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim iUserID As Integer
Dim sMsgId, sMsgSubject, sMsgDateSent, sMsgRead, sMsgFrom, sFirstname As String
iUserID = Session("UserID")
Dim cn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString)
Dim cmd As New SqlCommand()
Dim tblRow As TableRow
Dim tblCell1 As TableCell
Dim tblCell2 As TableCell
Dim tblCell3 As TableCell
Dim tblCell4 As TableCell
tblRow = New TableRow
tblCell1 = New TableCell
tblCell1.Text = ""
tblRow.Cells.Add(tblCell1)
tblCell2 = New TableCell
tblCell2.Text = "From"
tblRow.Cells.Add(tblCell2)
tblCell3 = New TableCell
tblCell3.Text = "Subject"
tblRow.Cells.Add(tblCell3)
tblCell4 = New TableCell
tblCell4.Text = "Received"
tblRow.Cells.Add(tblCell4)
tblMessages.Rows.Add(tblRow)
tblCell1 = Nothing
tblCell2 = Nothing
tblCell3 = Nothing
tblRow = Nothing
cmd.CommandText = "SELECT msg.msg_id, msg.msg_usr_from, usr.usr_firstname, msg.msg_subject, msg.msg_date_sent, msg.msg_read FROM messages msg inner join users usr on msg.msg_usr_to = usr.usr_id WHERE msg.msg_usr_to='" & iUserID & "'"
cmd.Connection = cn
cn.Open()
Dim r As SqlDataReader = cmd.ExecuteReader
Dim objControl As Button
While r.Read()
tblCell1 = New TableCell
tblCell2 = New TableCell
tblCell3 = New TableCell
tblCell4 = New TableCell
tblRow = New TableRow
sMsgId = CStr(r("msg_id"))
sMsgFrom = CStr(r("msg_usr_from"))
sFirstname = CStr(r("usr_firstname"))
sMsgSubject = CStr(r("msg_subject"))
sMsgDateSent = CStr(r("msg_date_sent"))
sMsgRead = CStr(r("msg_read"))
If sMsgRead = "N" Then
tblCell1.Text = "<img width=30px src=images/new_email.png>"
Else
tblCell1.Text = "<img width=30px src=images/email_open.png>"
End If
Dim objLinkbutton As
tblRow.Cells.Add(tblCell1)
tblCell2.Text = sFirstname
tblRow.Cells.Add(tblCell2)
tblCell3.controls.add( HYPERLINK HERE!!!
tblRow.Cells.Add(tblCell3)
tblCell4.Text = FormatDateTime(sMsgDateSent, DateFormat.LongDate)
tblRow.Cells.Add(tblCell4)
If sMsgRead = "N" Then
tblCell2.Font.Bold = True
tblCell3.Font.Bold = True
tblCell4.Font.Bold = True
End If
tblMessages.Rows.Add(tblRow)
tblCell1 = Nothing
tblCell2 = Nothing
tblCell3 = Nothing
tblCell4 = Nothing
tblRow = Nothing
End While
r.Close()
cn.Close()
cn = Nothing
r = Nothing
cmd = Nothing
End Sub
Protected Sub viewmessage(messageid As String)
Context.Items("messageid") = "messageid"
Server.Transfer("viewmessage.aspx")
End Sub
End Class
You have two choices, as I see it.
Massage the data set so it contains the complete URI, with the ID, and then bind to a grid
Use a routine to create the URI and then bind the grid via row binding
Continuing hand binding the table, using hyperlink controls
All are easy enough to do, but the #3 option is the least "ASP.NET" like. I am not fond of hand building tables, when I can do the same with a control, simply by either a) altering the data before bind or b) stopping on the row binding event and adding information.
Use query string to store the id value of the selected link and redirect to the page you want.
try something like this:
Dim a As New HyperLink()
a.Text = "your text"
a.NavigateUrl = "yourPage.aspx?idMsg=" + r["msg_id"]
tblCell3.controls.add(a)

compare the content of 2 gridviews in one aspx page

we need to compare the content of 2 identical gridviews and extract rows that differ in a third gridview, is this doable?
i tried a lot but faced no luck, please help me.
at our office we take daily backup of ASP.net application ms access backend
for the next few days we need to evaluate the changes made to records in the database tables
at the end of each day i want to compare 2 access databases first database is the backup of yesterday and second database is the backup of today
i thought of the following algorithm, please read carefully and tell me how to proceed to compare the datatables / gridviews
i need to display th rows / cells containing the differences / updates / deleted data
comparing two ms access backend databases of an asp.net web application
my team and myseld figured it out
Imports System.Data
Imports System.Data.OleDb
Partial Class MoKoTrack
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myDB = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|databaseName.mdb;Persist Security Info=True")
Session("CurrentDB") = myDB
myDB.open()
Dim mytables = myDB.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, New Object() {})
Dim CurrentTable As String
For i = 1 To mytables.Rows.Count
CurrentTable = mytables.Rows(i - 1).Item(2).ToString
If CurrentTable.Contains("Backup") Then CompareTable(CurrentTable, mytables.Rows(i - 1).Item(3).ToString)
Next i
' Dim myGrid As New GridView
'myGrid.DataSource = mytables
'myGrid.DataBind()
'Me.Form.Controls.Add(myGrid)
'myDB.Close()
End Sub
Sub CompareTable(ByVal BackupTableName As String, ByVal myPrimKey As String)
Dim OriginalTable As New DataTable
Dim BackupTable As New DataTable
Dim ModificationsTable As New DataTable
Dim AddedTable As New DataTable
Dim DeletedTable As New DataTable
Dim myDB = Session("CurrentDB")
Dim FinalSQLString = "SELECT * FROM [" + BackupTableName + "]"
Dim myDBCommand = New OleDbCommand(FinalSQLString, myDB)
Dim myReader As IDataReader = myDBCommand.ExecuteReader()
BackupTable.Load(myReader)
Dim OriginalTableName = Left(BackupTableName, Len(BackupTableName) - 6)
Dim FinalSQLString2 = "SELECT * FROM [" + OriginalTableName + "]"
Dim myDBCommand2 = New OleDbCommand(FinalSQLString2, myDB)
'Generate a temporary reader to get the number of cases
Dim myReader2 As IDataReader = myDBCommand2.ExecuteReader()
OriginalTable.Load(myReader2)
Dim myPrimColumn(0) As DataColumn
myPrimColumn(0) = OriginalTable.Columns(myPrimKey)
OriginalTable.PrimaryKey = myPrimColumn
Dim myPrimColumn2(0) As DataColumn
myPrimColumn2(0) = BackupTable.Columns(myPrimKey)
BackupTable.PrimaryKey = myPrimColumn2
AddedTable = OriginalTable.Clone
DeletedTable = OriginalTable.Clone
ModificationsTable = OriginalTable.Clone
ModificationsTable.PrimaryKey = Nothing
Dim CurrentVal As String
For i = 0 To OriginalTable.Rows.Count - 1
CurrentVal = OriginalTable.Rows(i).Item(myPrimKey).ToString
Dim foundRow As DataRow = BackupTable.Rows.Find(CurrentVal)
If foundRow IsNot Nothing Then
For t = 0 To OriginalTable.Columns.Count - 1
If Not foundRow.Item(t).ToString = OriginalTable.Rows(i).Item(t).ToString Then
ModificationsTable.ImportRow(OriginalTable.Rows(i))
'ModificationsTable.Rows(ModificationsTable.Rows.Count - 1).Item(t) = ModificationsTable.Rows(ModificationsTable.Rows.Count - 1).Item(t) & "Modified"
ModificationsTable.ImportRow(foundRow)
End If
Next
Else
AddedTable.ImportRow(OriginalTable.Rows(i))
End If
Next
For i = 0 To BackupTable.Rows.Count - 1
CurrentVal = BackupTable.Rows(i).Item(myPrimKey).ToString
Dim foundRow As DataRow = OriginalTable.Rows.Find(CurrentVal)
If foundRow Is Nothing Then
DeletedTable.ImportRow(OriginalTable.Rows(i))
End If
Next
If AddedTable.Rows.Count > 0 Then
Dim myLabel As New Label
myLabel.Text = "<br/> The following records were added to table " & OriginalTableName & "<br/> <br/>"
Me.form1.Controls.Add(myLabel)
Dim myGrid As New GridView
myGrid.DataSource = AddedTable
myGrid.DataBind()
Me.form1.Controls.Add(myGrid)
End If
If ModificationsTable.Rows.Count > 0 Then
Dim myLabel As New Label
myLabel.Text = "<br/> The following records were modified in table " & OriginalTableName & "<br/> <br/>"
Me.form1.Controls.Add(myLabel)
Dim myGrid As New GridView
myGrid.DataSource = ModificationsTable
myGrid.DataBind()
Me.form1.Controls.Add(myGrid)
End If
If DeletedTable.Rows.Count > 0 Then
Dim myLabel As New Label
myLabel.Text = "<br/> The following records were deleted from table " & OriginalTableName & "<br/> <br/>"
Me.form1.Controls.Add(myLabel)
Dim myGrid As New GridView
myGrid.DataSource = DeletedTable
myGrid.DataBind()
Me.form1.Controls.Add(myGrid)
End If
End Sub
End Class
I usually compare it using LINQ
This will give you a head start
var SearchResults1 = from u in YourDB.YourUserTable1
orderby u.YourColumn
select u;
GridView1.DataSource = SearchResults1;
GridView1.DataBind();
var SearchResults2 = from u in YourDB.YourUserTable2
orderby u.YourColumn
select u;
GridView2.DataSource = SearchResults2;
GridView2.DataBind();
var SearchResults3 = from u1 in SearchResults2
where !(from u2 in SearchResults1
select u2.YourTablePrimaryKey).Contains(u1.YourTablePrimaryKey)
orderby u1.YourColumn
select u1;
GridView3.DataSource = SearchResults3;
GridView3.DataBind();
You can further elaborate SearchResults 3 if you want like comparing whats in SearchResults1 but not in SearchResults2 and vice versa

Resources