|
-
Jun 17th, 2005, 02:02 AM
#1
Thread Starter
Fanatic Member
-
Jun 17th, 2005, 02:22 AM
#2
Re: dataset or datareader?
Datareader would be fastest for read-only data.
-
Jun 17th, 2005, 03:15 AM
#3
Thread Starter
Fanatic Member
Re: dataset or datareader?
how can i use sqldatareader with stored procedure
If a post has helped you then Please Rate it!
-
Jun 17th, 2005, 05:19 AM
#4
Re: dataset or datareader?
VB Code:
Public Sub ReadMyData(myConnString As String)
Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
Dim myConnection As New SqlConnection(myConnString)
Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
While myReader.Read()
Console.WriteLine((myReader.GetInt32(0) & ", " & myReader.GetString(1)))
End While
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
myConnection.Close()
End Sub 'ReadMyData
You can easily modify the mycommand object to work with an SP of your choice.
-
Jun 17th, 2005, 05:21 AM
#5
Re: dataset or datareader?
Ah, I found an example:
VB Code:
Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=northwind")
Dim salesCMD As SqlCommand = New SqlCommand("SalesByCategory", nwindConn)
salesCMD.CommandType = CommandType.StoredProcedure
Dim myParm As SqlParameter = salesCMD.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15)
myParm.Value = "Beverages"
nwindConn.Open()
Dim myReader As SqlDataReader = salesCMD.ExecuteReader()
Console.WriteLine("{0}, {1}", myReader.GetName(0), myReader.GetName(1))
Do While myReader.Read()
Console.WriteLine("{0}, ${1}", myReader.GetString(0), myReader.GetDecimal(1))
Loop
myReader.Close()
nwindConn.Close()
-
Jun 17th, 2005, 05:21 AM
#6
Re: dataset or datareader?
-
Nov 15th, 2005, 11:33 PM
#7
Thread Starter
Fanatic Member
Re: dataset or datareader?
If a post has helped you then Please Rate it!
-
Nov 16th, 2005, 08:23 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|