Click to See Complete Forum and Search --> : [RESOLVED] dataset or datareader?
VBKNIGHT
Jun 17th, 2005, 02:02 AM
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! :wave:
mendhak
Jun 17th, 2005, 02:22 AM
Datareader would be fastest for read-only data.
VBKNIGHT
Jun 17th, 2005, 03:15 AM
how can i use sqldatareader with stored procedure
mendhak
Jun 17th, 2005, 05:19 AM
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.
mendhak
Jun 17th, 2005, 05:21 AM
Ah, I found an example:
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()
mendhak
Jun 17th, 2005, 05:21 AM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingstoredprocedureswithcommand.asp
VBKNIGHT
Nov 15th, 2005, 10:33 PM
thanks man.
mendhak
Nov 16th, 2005, 07:23 AM
Wow, 5 months later. :afrog:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.