473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# Web-App: Sql query way tiring for sync()

16
I wanna help on the following aspect of SQL data retrieval which requires one to retrieve data from remote SQL server site asynchronously.

Im building a c# application. I want to retrieve record (network packets info) from the remote computer that is located on the same subnet as the client (from which it receives the request). Since due to the large volume of data which may include more than 20,000 rows in each table .....
Expand|Select|Wrap|Line Numbers
  1. void results()
  2.         {
  3.  
  4.             dataGridView1.DataSource = null;
  5.  
  6.  
  7.  
  8.             DataSet ds = new DataSet();
  9.  
  10.  
  11.             SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM " + state, rc);
  12.  
  13.          // where rc is the SQL connection point that exists b/w my sql client and SQL server (remote machine) meaning the connection is already established when i execute the command
  14.  
  15.  
  16.             adapter.Fill(ds);
  17.             dataGridView1.DataSource = ds.Tables[0];
  18.  
  19.         }

Is simply too slow for comfort and more importantly this function halts the execution of more user controlled events like clicking other buttons and moving cursor. The whole control on the panel is lost during the sql command execution and its bloody annoying .

So does anyone know how could i make fun() behave asynchronously.

thxs.....
Nov 27 '07 #1
3 1568
Here are a couple of things to consider first before we continue figuring out the best way to resolve your issue...

1.) Are you trying to fill a gridview control with 20,000 items on the same page?

2.) Have you considered using grid view paging with maybe 100 items per page?

I ask you this because if you are trying to bind 20,000 rows of data from a SQL database into an ASP.NET Server Control it's going to take a while and may lock up your app (which seems to be happening).

Also, I recommend using a stored procedure rather than in-line SQL statements because it will enhance the speed of your query dramatically.

If you would like sample code on gridview paging, SQL stored procedure example or more information about any of this please let me know and I will be more than willing to write a sample.
Nov 27 '07 #2
zonar00
16
Here are a couple of things to consider first before we continue figuring out the best way to resolve your issue...

1.) Are you trying to fill a gridview control with 20,000 items on the same page?

2.) Have you considered using grid view paging with maybe 100 items per page?

I ask you this because if you are trying to bind 20,000 rows of data from a SQL database into an ASP.NET Server Control it's going to take a while and may lock up your app (which seems to be happening).

Also, I recommend using a stored procedure rather than in-line SQL statements because it will enhance the speed of your query dramatically.

If you would like sample code on gridview paging, SQL stored procedure example or more information about any of this please let me know and I will be more than willing to write a sample.
the second option(2) seems more probable but firstly PL\SQL kinda thing is not retired in my case as im not supposed to do any datamining on the record. I just have to retrieve and display them in datagrid thats it so i think simple SQL query should do the trick.

im interested in knowing that like in case of restricting the record for 100 count can be done with the help of sql query using the count keyword but dnt u think going in viewing total records in breaks of 100 would take too long again......
Nov 27 '07 #3
Okay so paging is the way you would like to have the users view the records on the page as well as use in-line sql.

Here is a small example of how you can accomplish this task using C# ASP.NET 2.0 Visual Studio 2005 (or Visual Web Developer - free download from http://msdn2.microsoft.com/en-us/express/aa700797.aspx) and the SQL Northwind Database. This example also uses post backs on the page, so if you need it to be asyncronous we can add this to the example.

Quick Note: my team and I would have used a different approach, we would have used SQL Stored Procedure or Strongly Typed DataSets.

ASPX Page
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml"> 
  5. <head runat="server">
  6. <title>GridView Example</title>
  7. </head>
  8. <body>
  9. <form id="form1" runat="server">
  10. <asp:ScriptManager ID="ScriptManager1" runat="server" />
  11. <div>
  12. <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="100" OnPageIndexChanging="GridView1_PageIndexChanging">
  13. <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  14. <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  15. <EditRowStyle BackColor="#999999" />
  16. <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
  17. <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  18. <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  19. <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  20. </asp:GridView>
  21. &nbsp;</div>
  22. </form>
  23. </body>
  24. </html>
  25.  
C# ASP.NET 2.0 CODE BEHIND PAGE
Expand|Select|Wrap|Line Numbers
  1.  
  2. using System; 
  3. using System.Data;
  4. using System.Configuration;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. // DON'T FORGET TO ADD THIS NAMESPACE
  12. using System.Data.SqlClient;
  13.  
  14. public partial class _Default : System.Web.UI.Page 
  15. {
  16. // OF COURSE THIS SHOULD BE IN YOUR WEB.CONFIG FILE & ENCRYPTED
  17. string conString = "Server=SWBC-DVLP2\\SWBCSQL;Database=Northwind;User ID=northwindtest;Password=NORTHWINDTEST;";
  18.  
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. Bind_GridView1();
  22. }
  23.  
  24. public void Bind_GridView1()
  25. {
  26. SqlConnection sqlConn = new SqlConnection(conString);
  27. SqlDataAdapter sqlDA = new SqlDataAdapter("SELECT OrderID, CustomerID, OrderDate, ShippedDate FROM Orders", sqlConn);
  28. DataSet ds = new DataSet();
  29. sqlDA.Fill(ds, "Orders");
  30. GridView1.DataSource = ds;
  31. GridView1.DataBind();
  32. }
  33.  
  34. public void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  35. {
  36. GridView1.PageIndex = e.NewPageIndex;
  37. Bind_GridView1();
  38. }
  39.  
  40. }
  41.  

Please let me know if this example is enough, I can provide more details for you if need be. There is a whole lot of functionality when it comes to gridviews and how you can use them (Hierarchical GridViews, Paging, Sorting, Tabbed GridViews using AJAX ToolKit Tab Control, Asyncronous PostBacks & MORE) so let us know exactly what your looking for. As for the example, hope it helps!

- Aaron Sandoval
"remember: There's a thin line between good | great..."
Nov 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Phillip J. Eby | last post by:
PEP: 333 Title: Python Web Server Gateway Interface v1.0 Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/08/27 17:30:09 $ Author: Phillip J. Eby <pje at telecommunity.com> Discussions-To:...
2
by: PatrickSA | last post by:
Hi, Am new to web services, so apologies for the basic nature of the question - and apologies in advance if this is the wrong newsgroup. We're building a new web service and I'm looking around...
8
by: John Baker | last post by:
Hi: I am URGENTLY in need of some book or web site OR tool that will help me integrate a relatively simple access application into a web page or pages. This is a time recording system (by...
0
by: Erick Lopez | last post by:
When I send my web page to browser in ouput windows recibe this message and the web page the error BC32400 Please Help me Auto-attach to process ' aspnet_wp.exe' on machine 'TABLET'...
2
by: Anna | last post by:
I added a small Web.Config file to the root of my website so that I could view errors on a machine other than the server: <configuration> <system.web> <customErrors mode="Off" /> </system.web>...
5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
7
by: Jonas | last post by:
Hi. I'm trying to develop a web custom control that uses a programmatically created treeview. My problem is that I get an exception when I try to render the control. With properties do I have to...
2
by: Jeff | last post by:
Hey asp.net 2.0 My asp.net 2.0 project has got a assembly load problem: Some of my web.config settings: <membership defaultProvider="AH_MembershipProvider" userIsOnlineTimeWindow="15">
20
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I was executing the steps given in http://suppor.microsoft.com/kb/308359 for testing a sample web service application. However, the following line gives a compilation error: localhost.Service1...
2
by: =?Utf-8?B?YW5vbg==?= | last post by:
I am not sure if this is the right forum. Environment : Windows server 2008, IIS 7.0 I get the 'Could not load the file or assembly 'blowery.web.httpCompress' or one of its dependencies. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.