Click here to Skip to main content
15,867,686 members
Everything / DataTable

DataTable

DataTable

Great Reads

by Alex Pumpet
A simple program for comparing table data from two sources - SQL databases, Excel, CSV or XML-files
by Jovan Popovic(MSFT)
Reordering table rows using drag and drop functionality with jQuery DataTables plug-in in ASP.NET MVC applications
by Massimo Fabiano
I know that "returning DataSets from WebServices is the spawn of Satan" but...
by Proneetkumar Pradeep Ray
JQuery Datatable (Dynamic columns) populate after Ajax JSON response via server side processing - Using EF Raw SQL query

Latest Articles

by DiponRoy
The aim of this helper class is to divide a large IEnumerable into multiple small list.
by DiponRoy
The aim of this helper class is to divide a large datatable into multiple small datatables.
by Stefan Vincent Haug
Helper method to apply sorting from DataTables.js parameters in C#
by WyoMetz
Simple and easy paging of a WPF DataGrid with DataTable and LINQ queries

All Articles

Sort by Score

DataTable 

20 Mar 2018 by Alex Pumpet
A simple program for comparing table data from two sources - SQL databases, Excel, CSV or XML-files
23 Apr 2012 by Jovan Popovic(MSFT)
Reordering table rows using drag and drop functionality with jQuery DataTables plug-in in ASP.NET MVC applications
28 Sep 2016 by Massimo Fabiano
I know that "returning DataSets from WebServices is the spawn of Satan" but...
16 Aug 2018 by Proneetkumar Pradeep Ray
JQuery Datatable (Dynamic columns) populate after Ajax JSON response via server side processing - Using EF Raw SQL query
2 Jul 2014 by Chakravarthi Elchuri
Display data in Multi nested gridview using C# in ASP.NET
7 Apr 2018 by #realJSOP
An example of evolving code to fit new demands
12 Oct 2016 by SrikantSahu
Jquery Datatable already provides individual column filters. However, we can leverage that to create our custom filter that works similar to Excel filter.
24 Jan 2011 by Henry Minute
You'll laugh when I point out the problem.Here is the modified code (I have changed a couple of your variable names to make it clearer): int row1 = (this.agentsDataGridView.CurrentCell.RowIndex); int col1 = (this.agentsDataGridView.CurrentCell.ColumnIndex); ...
7 Mar 2011 by Orcun Iyigun
SO here is what you need to do;You can do it one row at a time in to the database.Mainly this method is just opening a connection to the access db, going through each row in the gridview datasource (if you create the datasource on the fly you might need to recreate the table at the...
7 May 2014 by ZurdoDev
dat3 needs to have columns. Currently it does not have any columns which is why you get the error. Add the columns first and then call LoadDataRow.http://msdn.microsoft.com/en-us/library/kcy03ww2(v=vs.110).aspx[^]
31 May 2016 by Karthik_Mahalingam
try thisDataTable dt1 = new DataTable(); dt1.Columns.Add("ID"); dt1.Columns.Add("Name"); dt1.Rows.Add(101, "ABC"); dt1.Rows.Add(102, "XYZ"); dt1.Rows.Add(103, "MNO"); dt1.Rows.Add(104, "PQR"); DataTable dt2 = new DataTable(); ...
28 Apr 2011 by Albin Abel
If you know about Personalization you can very well to store and retrieve user specific informations instead of session. However those objects needs to be serializable. This is an alternate suggestion. If you already know about personalization in .Net i don't need to write more on it :)
13 Apr 2012 by VJ Reddy
The reason is in the SortedList, the key is added as an integer. So, the order will be 7, 31, 32, 33. Whereas, in the DataTable the value is text, hence, the order is 31e, 32e, 33e, 7i.To get the same sort as in data table, add the key as text i.e.emp.Add(key, type);where key is 31e,...
25 Apr 2012 by VJ Reddy
The following LINQ query can be used to obtain the above resultsvoid Main(){ DataTable accData = new DataTable(); accData.Columns.Add("Date",typeof(DateTime),null); accData.Columns.Add("Credit",typeof(double),null); accData.Columns.Add("Debit",typeof(double),null); ...
1 Apr 2016 by Dave Kreskowiak
This problem cannot be solved by threading. Without using locking, you cannot guarantee the order in which threads run. You CAN get a thread order like 1, 2, 3, 1, 3, 2, 3, 1, 2, 1, ...Introducing locking to get the correct order just makes these threads execute synchronously, no different...
13 Oct 2018 by Stefan Vincent Haug
Helper method to apply sorting from DataTables.js parameters in C#
27 Oct 2010 by Andrew Rissing
Technically, the best approach here for speed and flexibility is to do the following:public class TestClass{ private const string EMP_ID = "EmpId"; public void MyTestMethod() { //GetData fetches data from the database using a SQL query DataTable dt =...
8 Nov 2010 by David Ewen
The last 2 linesbyte[] data = (byte[])dt.Rows[0][0];richTextBox1.Rtf = System.Text.Encoding.Unicode.GetString(data);Should berichTextBox1.Rtf = dt.Rows[0][0].ToString();There is no need to try to convert the string to a byte array and back to a string.
13 Jan 2011 by Simon_Whale
import the excel data and run an outer join queryAccess Outer join query[^]
17 Jul 2011 by thatraja
I found same other things in CP, just take a look at theseAnother Sudoku Solver and Generator[^]Sudoku Algorithm: Generates a Valid Sudoku in 0.018 seconds[^]Sudoku Algorithm: Strategies to Avoid Backtracking[^]Sudoku[^]
17 Jul 2011 by Dave Kreskowiak
And if you can't find anything here to your liking, there's a TON of them on CodePlex. Results...[^]
4 Aug 2011 by Wonde Tadesse
Both give the desired out put. Except DataReader relatively faster but has cost due to it works with exclusive database connection. If you want work with disconnected scenario, then Datatable or Dataset is much preferable. For more look this MSDN forum DataTable Vs DataReader[^]
10 Dec 2011 by Monjurul Habib
Read the following links:Do more with a DataTable and improve performanceUsing DataTables More for Improving Performance Hope you will get your idea from the above links.
10 Dec 2011 by Abhinav S
You could write an extension method that can be called on the datatable and does the calculations.You don't really need to do calculations on the datatable itself. On the other hand, it might actually be worthwhile to calculate the moving averages at the query level as well.
21 May 2012 by Prasad_Kulkarni
Please refer:Export the Datatable records to Excel sheet in C#.net:Export to EXCEL from Datatable in C#.Net[^]Similar discussion: Click here[^]Export a DataTable to Excel in ASP.NET[^]Following link shows how to import or export DataTable to Excel or HTML files by using...
24 May 2012 by Wendelius
Your code looks valid at a glance. When you call the ExecuteNonQuery, take the return value into a variable. So modify your code to...int rowsaffected = command1.ExecuteNonQuery();...Now using debugger, check what is the value of rowsaffected. It should be the total amount of rows.If...
24 May 2012 by Maciej Los
The command DELETE FROM Onlineis correct, but i prefer to use TRUNCATE[^] (see my comment to Mark Nischalke anser).In my opinion, the problem is in the below procedure: private void Form1_FormClosing(Object sender, FormClosingEventArgs e) { StopServer(); ...
4 Sep 2014 by ASP.NET Community
Here is a simplified class to create Excel file from DataTable just Pass DataTable and Preferred location on server to generate. Call the
17 Nov 2013 by Hazem Torab
Generate reasonable sample data for you GridView without using databases.
3 Mar 2014 by CHill60
The problem with line DataTable table3 = CompareTwoDataTable(DataTable table1,DataTable table2); is that you have left the type definitions in the call - cut&paste error perhaps?Change it to DataTable table3 = CompareTwoDataTable(table1,table2);
8 Apr 2014 by Guruprasad.K.Basavaraju
Here is an example that you should be able to use.http://jquery-datatables-column-filter.googlecode.com/svn/trunk/dateRange.html[^]
18 Apr 2014 by Guruprasad.K.Basavaraju
I am not sure of Bootstrap but you can simply apply the same class to second TD using the Javascripts after the table is created.$(function() { $(".table-class tr").each(function() { $(this).find('td:eq(2)').addClass("hidden-xs"); });});
18 Jun 2014 by Thanks7872
The first DataTable you add will be the first one, and so on. Its obvious that it will be tables[0] in your case.Regards..
18 Aug 2014 by Karthik Harve
Hi One rule with FOREACH loop is that, you cannot modify the loop collection. So try using FOR loop.try this.for(int i=0; i
10 Feb 2015 by Richard Deeming
You can do it with LINQ, but it's not pretty:DataTable merged = fieldsforDynamicGroup.AsEnumerable() .Where(a => Dtlists.AsEnumerable() .Select(b => b.Field("ListName") ?? string.Empty) .Any(list => list.Contains(a.Field("FieldName"))) ...
1 May 2016 by Karthik_Mahalingam
The below code will take care of casting exception, but you will have to make sure that the table has valid numbersdouble[,] f = new double[10000, 10000]; foreach (DataColumn dc in dt.Columns) { h = h + 1; for (int i = 0; i
1 Mar 2020 by Maciej Los
You have to use PIVOT[^]. SELECT LabelText, [judge1], [judge2], [judge3]... FROM ( SELECT *, CONCAT('judge', CONVERT(VARCHAR(50), ROW_NUMBER() OVER(PARTITION BY qst_id ORDER BY judge_id)) AS judgeNo FROM YoutTable ) dt PIVOT(SUM(Score)...
3 Jun 2020 by Maciej Los
Quote: I use open XML library Sorry, but you're wrong. You're using EPPlus, because OpenXml does not have built-in LoadFromDataTable method. All you have to do is: 1. create Excel file (workbook) 2. loop through the DataRows collection of...
17 Jun 2020 by #realJSOP
try this: select max(case when isnumeric(roll_no)=0 then 0 else roll_no end) as max_roll if there's a chance your data will not always have a simple numeric value (in other words: 1 2 3b you probably want to try this SELECT...
9 Dec 2023 by Dave Kreskowiak
DEBUGGER! Ruin the code under the debugger and set a breakpoint on the line that fills the DataSet. Execture the code one line at a time and hover the mouse over variables to see their content. You could have figured this out in seconds! The...
6 Feb 2011 by Espen Harlinn
Since you are working with asp.net you should avoid using excel to perform your work.Use a library like EPPlus[^] to create your excel files. It's an open source project hosted on CodePlex.Using excel to perform your work tends to work beutifully during development, and cause all sorts...
13 Apr 2011 by Pong D. Panda
Google!http://msdn.microsoft.com/en-us/library/aa479350.aspx[^]
8 May 2011 by Wonde Tadesse
Ok. Here is what you looking for. Add the following method in addition to the methods that already have it.Call GroupbyDeptAndSumNetPay() in the main entry. /// /// Group by Department and Sum the Net Pay for each department /// public void GroupbyDeptAndSumNetPay() { ...
28 Apr 2011 by wooga111
Hello All,Here is my scenario:I am using VS2010 and have a ASP.NET web application. On my page I am using a WebUserControl that uses a modelpopupextender to allow a user to select contacts from a list. All of this is contained in a asp.net formview.After a user selects some contacts...
22 Jun 2011 by Prerak Patel
Easiest way,Line 7: strSQL = "SELECT * FROM data.csv WHERE column1 = '" + sDataValue.Replace("'", "''") + "'";Proper way, Use parameterised query.Line 7: strSQL = "SELECT * FROM data.csv WHERE column1 = ?";Line 8: OdbcCommand cmdSelect = new OdbcCommand(strSQL, CsvConn); ...
3 Oct 2011 by Adam Covitch
It is common to configure back-end database tables to contain a column with an auto-generated ID unique to each row. This tip describes how to sync the ID generated by the database back to the application layer.
6 Sep 2011 by Wendelius
You could try to add HDR=No;IMEX=1 to your connection string. If you don't have a header row and in case you have mixed data types in columns.string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Sheets/DataSheet.xls;Extended Properties=\"Excel 12.0;HDR=No;IMEX=1\";";
20 Nov 2011 by Mehdi Gholam
I have found a possible solution here : http://www.dotnetmonster.com/Uwe/Forum.aspx/winform-data-binding/1042/BindingSource-Filter-fails-when-datasource-derives[^]
23 Feb 2012 by Maciej Los
First of all you need to understand Scope of variables[^]And here[^] you'll find complete example (ReadXml & WriteXml).
7 Apr 2012 by Reza Ahmadi
Hi,Take a look at this post:http://msdn.microsoft.com/en-us/library/tat996zc%28v=vs.100%29.aspx[^]Cheers
21 May 2012 by Abhinav S
Try DataSet to Excel File Conversion using ExcelLibrary[^].This discussion[^] might also be of some interest to you.
28 May 2012 by taha bahraminezhad Jooneghani
you can use Chart.DataBindTable method like this:Chart1.DataBindTable(myReader, "SalesName");all things about chart binding is here:http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx[^]
23 Jul 2012 by StianSandberg
I can recommend ClosedXml. It's open source and easy to use..You download it from codeplex and add reference in your project.var wb = new XLWorkbook();wb.Worksheets.Add(yourDataTable);wb.SaveAs("myExcelFile.xlsx");PS.. ClosedXml only supports .xlsx!
25 Sep 2012 by vasim sajad
create a datatable with same structure of resultie. DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(int)); dt.Columns.Add("Name", typeof(int)); dt.Columns.Add("MobileNumber", typeof(int)); ...
25 Sep 2012 by VIPR@T
Hi,See the below link.It might be help you to solve your problem.Convert Linq Query Result To DataTable[^]Thanks,Viprat
27 Nov 2012 by Aadhar Joshi
Creating job in sql server which automates taking backup of all stored procedures and functions in physical drive.
8 May 2013 by Kschuler
My first thought is that you add a column. For each row you generate a random number and populate that column with it. Then sort by that column.Google Results for Generating a Random Number[^]
8 May 2013 by CHill60
Try reading the data with the following SQL SELECT TOP 100 percent * FROM [yourtable] ORDER BY newid()You can change the 100 percent - I just assumed you'd want the entire table.You could also drop the percent to get e.g. 100 questions.With acknowledgements to Ralph Shillington[^]
17 Sep 2013 by CodeBlack
You can create one method for dropdownlist binding and one method which gets data for dropdownlist as mentioned below : protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.BindData(); } ...
6 Nov 2013 by OriginalGriff
The problem is that you are using just one DataTable, and assuming that assigning a static variable to that table will copy the contents - it doesn't. It sets the reference to the table, so if you later change the table content (as you do each time through the for loop) it "updates" all the...
3 Jan 2014 by idenizeni
Yes, you can do this by adding a column to your DataTable that has an expression defined.Like so...DataTable tbl = new DataTable("TestTable");DataColumn c = new DataColumn("Col1", typeof(Int32));tbl.Columns.Add(c);c = new DataColumn("Col2",...
3 Jan 2014 by Maciej Los
If dt is a Data.DataTable object, you can use something like that://get System.Data.EnumerableRowCollectionvar values = dt.AsEnumerable();//get total from myVal fieldint total = values.Sum(r=>r.Field("myVal"));//do calculations using linq queryvar PercSum = from v...
13 Jan 2014 by OriginalGriff
Perhaps it would help is you added the new row to the table?DataTable.NewRow[^] just creates a new blank row with the correct schema / columns...
14 Feb 2014 by OriginalGriff
Try:SELECT CASE WHEN field=0 THEN field ELSE 0 END AS Above FROM MyTable
6 Mar 2014 by george4986
Quote:Neewbie, happy to hear u have the result. final working code is updated belowprivate static DataTable CompareTwoDataTable(DataTable table1, DataTable table2){DataTable table3 = new DataTable();DataRow dr = null;string filterExp = string.Empty;for (int i = 0; i
10 Mar 2014 by george4986
dont know ur data structure of table, which u didn't postedtry this string colName = "name from database "; /////more than one columns take the count DataTable dt1 = new DataTable(); /////more than one column case use below code inside a loop with count of columns ...
5 Apr 2014 by Maciej Los
Try this:DECLARE @src TABLE(col1 VARCHAR(30), col2 VARCHAR(30), col3 VARCHAR(30))INSERT INTO @src (col1, col2, col3)VALUES('a', 'b', 'c')DECLARE @dst TABLE(id INT IDENTITY(1,1), col VARCHAR(30))INSERT INTO @dst (col)SELECT colValue AS colFROM ( SELECT colValue,...
13 Apr 2014 by Sergey Alexandrovich Kryukov
Please see this product: http://excelbuilderjs.com[^].If you do Web search, you will find advice to use ActiveX through the browser. Avoid it by all means. Not only it is not supported by all browsers, it is also utterly unsafe. Some security-savvy users won't come back to your site if they...
13 Apr 2014 by Manas Bhardwaj
In addition to what SA said, you might want to look at these example plugins:http://www.jquerybyexample.net/2012/10/export-table-data-to-excel-using-jquery.html[^]http://jsfiddle.net/lesson8/wVejP/[^]http://wsnippets.com/export-html-table-data-excel-sheet-using-jquery/[^]
15 Apr 2014 by Guruprasad.K.Basavaraju
Remember, your On Blur is ocnfigured to call submit which will post back the edited data to server.Below is the snippet in Jquery.jeditable.js file which does this./* add edited content and id of edited element to POST */ var submitdata = {}; ...
15 Apr 2014 by Guruprasad.K.Basavaraju
Change the below line in public ActionResult AjaxDataProvider(JQueryDataTableParamModel param)var result = from c in displayedCompanies select new[] { Convert.ToString(c.ID), c.Name, c.Address, c.Town };TOvar result = from c in displayedCompanies select new[] {...
15 Apr 2014 by Guruprasad.K.Basavaraju
I couldn't look into your code but the below should work.. replace #btnGuru with your button name.$("#btnGuru").click(function () { tableToExcel('myDataTable', 'W3C Example Table');});var tableToExcel = (function () { var uri = 'data:application/vnd.ms-excel;base64,' ...
20 May 2014 by DamithSL
you can select dynamically columns like x[mycolum] but your code fails because you return list of strings and trying to assign to a IEnumerable, try below var rows = dt2.AsEnumerable().Where(r => r.Field("Year") == year).Select(x => x[mycolum].ToString()).ToList();or...
31 Aug 2014 by Kornfeld Eliyahu Peter
&& is good for C like languages but not for SQL. For Select method you have to use SQL syntax and therefor replace && with AND...DataRow[] dr = dtRec.Select("Priority ='3' AND Recommendations='Replace Motor Bearings'");
10 Nov 2014 by DamithSL
try with LINQdt_Barcode = dt_Barcode.AsEnumerable() .GroupBy(r => new { Itemid = r.Field("Itemid"), PacktypeId = r.Field("PacktypeId")}) .Select(g => g.First()) .CopyToDataTable();Sample Test Code:void Main(){ DataTable dt_Barcode...
27 Nov 2014 by Maciej Los
Thank you for explanation.OK, if you can not use ADO.NET, you can join data using Linq query.Note: to be able to use below example, follow this link: How to: Implement CopyToDataTable Where the Generic Type T Is Not a DataRow[^] to create extension method.Dim dt As DataTable =...
8 Dec 2014 by George Jonsson
This is one way to do it.string input = "ABC_V3_Weekly_Abcdef_from_NOV_05_to_NOV_12";Regex regex = new Regex(@"from_(?[A-Z]{3})_(?[0-9]{2})_to_(?[A-Z]{3})_(?[0-9]{2})", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline...
6 Jan 2015 by Peter Leow
Refer: Read and write Open XML files (MS Office 2007)[^]
23 Jun 2015 by Suvendu Shekhar Giri
Try a stored procedure rather than a function.A sample stored procedure with parameter -DELIMITER $$DROP PROCEDURE IF EXISTS MyFirstSP$$CREATE PROCEDURE MyFirstSP(IN Id INT)BEGIN SELECT * FROM MyTable WHERE pk_id=Id;END$$You can follow this link to learn how to create a...
8 Jan 2016 by Maciej Los
There's few ways to achieve that. The best way to achieve that is to create Interface[^]. It depends on what you want to achieve.More:Walkthrough: Creating and Implementing Interfaces (Visual Basic)[^]Choosing Between Classes and Interfaces[^]Creating Classes in Visual Basic...
8 Jan 2016 by Wendelius
Concerning the question, you have at least two choices, you can declare the datatable in a module in order for it to be visible or you can pass an existing instance of the New_Yellow_Ball_Competition class to MainMenu class. If the single datatable is used widely in the program, it would make...
13 Sep 2016 by Maciej Los
Start here: c# - Convert JSON to DataTable - Stack Overflow[^] and/or here: Json to DataSet/DataTable[^]Recommended method:DataTable tester = (DataTable) JsonConvert.DeserializeObject(json, (typeof(DataTable)));
10 Nov 2016 by OriginalGriff
Why would you assume that i is valid for both dataGridView_auswahlen (row source) and table (row destination)?Since you are only transferring selected rows, unless your selection always starts with the first row and has no gaps, you will always get an exception.Instead of using an index,...
2 Jan 2017 by K-SIS
There is logical error.1. You are Filling in a loop so after every fill it will wipe previous filled data. (Data is replaced not appended.)2. connection is closed in loop so after first iteration the table object will be null.
18 Jul 2017 by Satya Prakash Swain
It worked for me 3 things require for resolvingcircular reference : 1. Apply [JsonIgnore] to navigational properties 2. In global.asax GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; 3....
10 Aug 2017 by Graeme_Grant
Looking at your code sample, the myList variable is not in the scope of your dt() method. You need to pass the result from ReadValues(...) method and pass it to your dt() method ... something like public static DataTable dt(IList myList) { // code goes here } Then to call: var table =...
24 Mar 2018 by RickZeeland
Here is an interesting library for reading and writing CSV files: GitHub - JoshClose/CsvHelper: Library to help reading and writing CSV files[^] You can also use LINQ, here is an example to calculate the average age: // Read CSV using LINQ static void ReadFileLinq(string fileName) {...
24 Mar 2018 by OriginalGriff
Start by working out how you are going to read the CSV data: there are a whole load of ways including writing your own CSV processor, but A Fast CSV Reader[^] is a good way to start. When you have the data, processing the column to get the average, median, or mean is trivial!
25 Mar 2018 by Maciej Los
It's easy to calculate median[^], because it's a middle/central value* of ordered list. * - for even number of values - it's an average of two values from middle of ordered list Follow the above link for further details. //case #1 - even number of values //int[] ages =...
6 May 2018 by OriginalGriff
DataTable.Select doesn't work like that: DataTable.Select Method (String) (System.Data)[^] - you are supplying a search criteria thjat is just "B1", or "B2", etc. - which isn't a search. You need to replace that with "ColumnName = 'B1'" and so on. Quote: Oh, so I have to replace the string...
6 May 2018 by Maciej Los
First of all: if, you would like to use foreach(...) loop, i'd move few lines of your code outside the foreach(...) loop due to the efficiency. Those are the lines, where you open Excel connection and fill in datatable. Second of all: you don't need second loop (foreach (DataRow r in...
4 Jun 2020 by Garth J Lancaster
What your issue says to me, is, you need to learn how to use the debugger or learn other methods for debugging. You have 2 areas of concern in your LINQ statement. 1) Quote: row.Cells[0].FormattedValue.ToString() == xlRange.Cells[xlRow, 1].Text ...
17 Jun 2020 by Gregory Gadow
This is a bit clunk but should work: SELECT MAX( CASE WHEN T.roll_no NOT LIKE '%[^0-9]%' THEN CAST(T.roll_no AS INT) ELSE NULL END ) FROM Table AS T This will look at each entry: if there are non-numeric characters in it, it will return...
29 Jun 2020 by Richard Deeming
As discussed in the comments, there's nothing obviously wrong with your code that I can see. It's probably an issue with your data, which we don't have access to. Check your browser's developer console for errors. Make sure the XHR request for...
23 Aug 2010 by Al-Farooque Shubho
Using SessionState is the solution.Let us assume that you have a Car object which some basic properties, along with a CarDetail object property, something like as follows:public class Car{ public string Make {get;set;} public string Model {get;set;} //Other basic properties ...
23 Aug 2010 by #realJSOP
Well, once you retrieve the data, it resides in a DataTable, correct? So just use LINQ to query the DataTable object.
9 Sep 2010 by Dave Kreskowiak
Well, you can't avoid the loop. It's got to be done somewhere.For something like this (I'm not a SharePoint guy) if the data is all on an SQL Server, I'd probably have the SQL Server do the work in a stored procedure since it's better optimized to handle large data sets.
26 Oct 2010 by shanawazway
Your scenario is like chat application.In which list is updated by the message.Try search chat application , u may have idea to update your GridView.