Results 1 to 8 of 8

Thread: [RESOLVED] dataset or datareader?

  1. #1

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    Resolved [RESOLVED] dataset or datareader?

    what was the best logical step and the fastest connection when i want
    to get recordset from sql database.

    my table name is "employee".
    i have a stored procedure named "getuser" parameter is @user.

    my goal is for login inform.wat to use datareader or dataset?

    pls give code how to populate a dataset and or datareader

    and how to compare user record value against given uservalue.

    thanks in advanced!

    If a post has helped you then Please Rate it!

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

    Re: dataset or datareader?

    Datareader would be fastest for read-only data.

  3. #3

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    Re: dataset or datareader?

    how can i use sqldatareader with stored procedure

    If a post has helped you then Please Rate it!

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

    Re: dataset or datareader?

    VB Code:
    1. Public Sub ReadMyData(myConnString As String)
    2.     Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
    3.     Dim myConnection As New SqlConnection(myConnString)
    4.     Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
    5.     myConnection.Open()
    6.     Dim myReader As SqlDataReader
    7.     myReader = myCommand.ExecuteReader()
    8.     ' Always call Read before accessing data.
    9.     While myReader.Read()
    10.         Console.WriteLine((myReader.GetInt32(0) & ", " & myReader.GetString(1)))
    11.     End While
    12.     ' always call Close when done reading.
    13.     myReader.Close()
    14.     ' Close the connection when done with it.
    15.     myConnection.Close()
    16. End Sub 'ReadMyData

    You can easily modify the mycommand object to work with an SP of your choice.

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

    Re: dataset or datareader?

    Ah, I found an example:

    VB Code:
    1. Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
    2.                                                    "Initial Catalog=northwind")
    3.  
    4. Dim salesCMD As SqlCommand = New SqlCommand("SalesByCategory", nwindConn)
    5. salesCMD.CommandType = CommandType.StoredProcedure
    6.  
    7. Dim myParm As SqlParameter = salesCMD.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15)
    8. myParm.Value = "Beverages"
    9.  
    10. nwindConn.Open()
    11.  
    12. Dim myReader As SqlDataReader = salesCMD.ExecuteReader()
    13.  
    14. Console.WriteLine("{0}, {1}", myReader.GetName(0), myReader.GetName(1))
    15.  
    16. Do While myReader.Read()
    17.   Console.WriteLine("{0}, ${1}", myReader.GetString(0), myReader.GetDecimal(1))
    18. Loop
    19.  
    20. myReader.Close()
    21. nwindConn.Close()

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

  7. #7

    Thread Starter
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619

    Re: dataset or datareader?

    thanks man.

    If a post has helped you then Please Rate it!

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

    Re: [RESOLVED] dataset or datareader?

    Wow, 5 months later.

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