Results 1 to 3 of 3

Thread: [RESOLVED] Can someone please comment this code for better understanding: reader = comm.ExecuteR

  1. #1

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Resolved [RESOLVED] Can someone please comment this code for better understanding: reader = comm.ExecuteR

    SqlCommand comm = new SqlCommand("SELECT * FROM UsrTbl, RelativeTable, IP_Table WHERE RelativeTable.UserID IN (SELECT UserID FROM UsrTbl WHERE UserName = @usrnmeLbl)", conn);
    comm.Parameters.AddWithValue("@usrnmeLbl", usrNmeLbl.Text);

    SqlDataReader reader = comm.ExecuteReader();
    //Check to see if the reader has data(Did the username exist in the database? We must check this
    if (reader.Read() != false)



    I see that comm is a SqlCommand object with the sql command parameters passed to it. Then I believe reader is a data reader object that is being told to reference something about the comm object. But what is it? Is it a property(ExecuteReader())?

    Or is it some kind of object creation method that then creates a new reader object that can act like an indexer.



    If someone could point out my misconceptions I would really appreciate it.

    Thanks in advance.

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Can someone please comment this code for better understanding: reader = comm.ExecuteR

    ExecuteReader() is one of the commonly used properties of a sqlCommand like .executeNonQuery() etc are. sqlDataReader is a forward only fast way of reading records from a database.

    SqlDataReader reader = comm.ExecuteReader(); is how you assign records from a ado command to a reader then access it methods etc to use the data.

    if reader.read
    if reader.hasRows
    while reader.read
    .......text += reader.item("xx")
    endwhile
    datagrid.datasource = reader()
    datagrid.databind
    reader.close()
    comm.close()

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] Can someone please comment this code for better understanding: reader = comm.ExecuteR


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width