Solved

How to sort and compare data from a SQL and an Access database

Posted on 2009-04-07
1
280 Views
Last Modified: 2013-12-17
I have a datagridview in my C#.net application that pulls data from a SQL database (id,name,details). I have functionality in my program that flags a record when I click on a row. When a row is flagged it stores the ID of the flagged row in my Access database. I need to be able to sort the grid listing those IDs that are stored in my access database by clicking on a button . The problem is I am working with data from a sql and access database. I need a mechanism that compares the ID in the access database with the data pulled from the sql database and list the records of the IDs that are stored in the Access database first. So the data is coming from the sql server but the IDs that are in the database are listed first
0
Comment
Question by:wademi
1 Comment
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24089021
You could use the merge method on the underlying datatables.
Assuming you retireve data from both SQL server & Access into two datatables, add a PK to each table, and then merge the Access table into the SQL Server table.

When you flag a record, again merge the Access table into the SQL Server table so that it's up to date.
    Random rand = new Random(1);
 
    DataTable sqlTable = new DataTable();
    sqlTable.Columns.Add("ID", typeof(int));
    sqlTable.Columns.Add("Date", typeof(DateTime));
    sqlTable.PrimaryKey = new DataColumn[]{sqlTable.Columns["ID"]};
 
    DataTable accessTable = new DataTable();
    accessTable.Columns.Add("ID", typeof(int));
    accessTable.Columns.Add("Flag", typeof(bool));
    accessTable.PrimaryKey = new DataColumn[] { accessTable.Columns["ID"] };
 
    for (int i = 0; i < 10; i++) {
      sqlTable.Rows.Add(i, DateTime.Now.AddMilliseconds(rand.Next(int.MinValue, int.MaxValue)));
    }
    sqlTable.AcceptChanges();
 
    for (int i = 0; i < 10; i++) {
      accessTable.Rows.Add(i, rand.Next(0, 2) == 0);
    }
    accessTable.AcceptChanges();
 
    sqlTable.Merge(accessTable);

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Disable Security Alert  popup in Winforms  embedded webbrowser. 1 57
VB.NET 2008 - SQL Timeout 9 34
Where is this file? 3 25
Amazon S3 Images with .Net 3 11
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question