troubleshooting Question

ASP.NET - How to read an SQL View into a sqlDataReader using a sqlCommand object

Avatar of colje
colje asked on
ASP
9 Comments1 Solution766 ViewsLast Modified:
I have created a view in an MS SQL v7 DB and would like to databind the contents to a list on a webform.

The code below works fine for a StoredProcedure but I want to know how to do it for a view.

Can it be done with a sqlDataReader and an sqlCommand ?

SAMPLE CODE
-----------
SqlConnection1.Open()
SqlCommand1.CommandType=System.Data.CommandType.StoredProcedure
SqlCommand1.CommandText = "vEmployees"
objReader = SqlCommand1.ExecuteReader()
lbxEmployees.DataTextField = "Name"
lbxEmployees.DataValueField = "ID"
lbxEmployees.DataSource = objReader
lbxEmployees.DataBind()
objReader.Close()
SqlConnection1.Close()
ASKER CERTIFIED SOLUTION
Ralf Klatt
Employee in Civil Service

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros