Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[4566] Replicating GetRows in .NET

Last post 04-30-2005 11:36 PM by DMarko1. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [4566] Replicating GetRows in .NET

    This thread is for discussions of Replicating GetRows in .NET.

    • Post Points: 0
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 04-12-2004 10:26 AM In reply to

    • dstorfer
    • Not Ranked
    • Joined on 04-12-2004
    • New Member
    • Points 5

    Well, you can do it that way, but why would you??

    I really don't think this article is a good idea at all. You are really showing people how NOT to use .NET to its fullest.  Why you would not drag a table on to your form and bind your dataset to it in 2-3 lines of code is beyond me.  Just because you CAN use this horribly archaic method of building HTML strings in code doesn't mean you should.  In fact, it should be avoided at all costs.  It's nearly akin to embedding SQL in your code rather than using stored procedures.

    As far as "control over display" you can really accomplish almost anything by using the format properties for each column and/or formatting the data in the SQL or Stored Proc.  If you needed something really crazy, you could even add some code to the ItemDataBound event.  That's a useful discussion in and of itself since you can also add formatting based on data elements - such as highlighting a row where a product is on sale or something like that.
    • Post Points: 0
  • 04-14-2004 5:10 AM In reply to

    defeats the purpose of ASP.NET OOprogramming

    please dont do what this article says....its the worst way to code in .NET
    • Post Points: 0
  • 04-27-2004 11:29 PM In reply to

    • ana
    • Not Ranked
    • Joined on 04-24-2004
    • New Member
    • Points 5

    Dividing data from a table in excel in new workshe

    Hi!

    I'm trying to divide data from a table in different excel worksheets files.

    Nombre    Dato           Nombre    Dato       Nombre    Dato
    a    1                   a           1               b              45
    a    10                 a           10             b              38
    b    45
    b    38
           
    • Post Points: 0
  • 05-04-2004 11:28 AM In reply to

    • binoj7
    • Not Ranked
    • Joined on 05-04-2004
    • New Member
    • Points 65

    Closing connection in the end?

    Forget about oops buddy, when ur migrating tons of code on a deadline.

    But do we need to close the connection in the end, cant the datatable sustain data when the collection is closed.

    • Post Points: 0
  • 01-18-2005 7:36 AM In reply to

    Completely missed the point of GetRows

    The whole point of GetRows is to open a conn, get the data and close the conn.
    not leave it open while you loop all data as you would exactly like a recordset.

    Pathetic.
    • Post Points: 0
  • 01-18-2005 9:10 AM In reply to

    • James Crowley
    • Top 10 Contributor
    • Joined on 12-07-2000
    • United Kingdom
    • Guru
    • Points 15,030
    • SystemAdministrator
    The author has indeed closed the connection at the end of the code (I've moved this further up now to make this clearer) - but the actual recordset is automatically closed the moment the call to the adapters "Fill" method is called - the recursive part of the code is on the "disconnected" DataSet.
    • Post Points: 0
  • 01-18-2005 9:12 AM In reply to

    • James Crowley
    • Top 10 Contributor
    • Joined on 12-07-2000
    • United Kingdom
    • Guru
    • Points 15,030
    • SystemAdministrator
    It sure can - I've just corrected the article to reflect this
    • Post Points: 0
  • 03-03-2005 2:42 AM In reply to

    • DMarko1
    • Top 500 Contributor
    • Joined on 09-19-2003
    • Addicted Member
    • Points 45

    You've entirely missed the whole point guys

    No, it's not pathetic and Yes, it is a technique that clearly your lack of insight allowed you to totally miss. Sure GetRows is what it is. Nevertheless, one project app fully benefited from this technique in a way any other technique would simply not do.

    This has nothing to do with portraying .NET's magnificent features or coding the “.NET way” All this shows is a unique methodology in "Replicating GetRows in .NET" in light of a particular need, when migrating a specific functionality from old ASP, and replicating as is to .NET, period!

    So if you don't agree or YOU missed the point, then it's an oversight on your part. Not considering, Developer Fusion deemed it worthy to be added to this site.
    • Post Points: 0
  • 04-29-2005 3:47 PM In reply to

    • T_Junky
    • Not Ranked
    • Joined on 04-29-2005
    • New Member
    • Points 10

    Same Concept in C#

    Do you have an example of this same concept using C#?
    • Post Points: 0
  • 04-30-2005 11:36 PM In reply to

    • DMarko1
    • Top 500 Contributor
    • Joined on 09-19-2003
    • Addicted Member
    • Points 45

    GetRows in C#

    <%@ Page Language="C#" Debug="False" Strict="True" Explicit="True" Buffer="True"%>

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>

    <script language="C#" runat="server">

    StringBuilder grTable;
    string sqlStr;
    int TotalRows, TotalFlds, c, r;

       void Page_Load(Object Source, EventArgs E) {

         sqlStr = "Select lname As LastName, fname As FirstName, emp_id As ID, hire_date As [Hired On] from Employee";
         SqlConnection objConnect = new SqlConnection ("server=(local);uid=sa;pwd=;database=Pubs;");
         SqlDataAdapter objDataAdapter = new SqlDataAdapter (sqlStr.ToString(), objConnect);
         DataSet objDS = new DataSet();

         //Create and Fill Info Datatable with results
         objDataAdapter.Fill (objDS,"Info");

         //Close and clear our connections
         objConnect.Close();
         objConnect = null;

         //Declare name variable as a DataTable
         DataTable GetRows = objDS.Tables ["Info"];

         //Get Table Info
         TotalRows = GetRows.Rows.Count;
         TotalFlds = GetRows.Columns.Count;
         grTable = new StringBuilder();
         grTable.Append ("<TABLE border=1 Width=60%>");
         grTable.Append ("<TR>");

         //Loop through data
         //Loop through the Columns Fields
         for (c = 0; c <= TotalFlds-1; c++) {
           grTable.Append ("<TD><B>" + GetRows.Columns[c].ToString() + "</B></TD>");
         }
         grTable.Append ("</TR>");

         //First header row is now closed and we loop through our database rows
         for (r = 0; r <= TotalRows-1; r++) {
           grTable.Append ("<TR>");
           grTable.Append ("<TD>" + GetRows.Rows[r][0].ToString() + "</TD>");
           grTable.Append ("<TD>" + GetRows.Rows[r][1].ToString() + "</TD>");
           grTable.Append ("<TD>" + GetRows.Rows[r][2].ToString() + "</TD>");
           grTable.Append ("<TD>" + GetRows.Rows[r][3].ToString() + "</TD>");
           grTable.Append ("</TR>");
         }
         grTable.Append ("</TABLE>");
         objDataAdapter = null;
         objDS = null;
       }
    </script>

    <html>
    <body>
    <%
     Response.Write (grTable.ToString());
     grTable = null;
    %>
    </body>
    </html>

    -Jimmy Markatos
    • Post Points: 0
Page 1 of 1 (11 items)