Datareader help

I want to retrieve multiple fields of data from my access db, but I don't want to use a datagrid or repeater.  The data that I will be accessing will only be one record that matches the select criteria.  I'm not sure how to do this.  Please help.

Here's my code bound to a datagrid:

Sub BindData()
      objConn.Open()
      objCmd = New OleDbCommand("SELECT * FROM Content WHERE ministryID=5", objConn)
      objRdr = objCmd.ExecuteReader()
      dgcontent.DataSource = objRdr
      dgcontent.DataBind()
      objRdr.Close()
      objConn.Close()
End Sub


I also need to know how to display this in the body.  I'm using asp.net v1.1, VB.NET.

Bobby
azyet24Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GavinMannionCommented:
To display it in the body just add some labels in the design time and then assign the values from the codebehind.


lblFirstName.Text = objRdr["FieldName"]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brdrokCommented:
just adding to GavinMannion statement:

I believe you have to cast it into a string or else it won't work.  Not 100% positive on it, but it wouldn't hurt:

lblFirstName.Text = (string) objRdr["FieldName"];

can't remember what the vb.net version is to cast something into a string type (CString() perhaps?).

0
azyet24Author Commented:
Is it better to use a literal or placeholder?  Or is there a better way?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

GavinMannionCommented:
I am not sure exactly what you mean, it all depends on what you are bringing back.

For a simple 1 record return you can setup your form nicely in a table and put some server side labels on it. Then just assign to the labels.

Unless you are hiding data at times and changing the format between records I see no reason to deviate from html tables and labels.
0
azyet24Author Commented:
I was able to get this to work as long as I don't limit the query.  However when I enter the Where ministryID=5, it gives me this error:

Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

Do you know what would be causing this?  Here's my code:

Sub BindData()
      objConn.Open()
      objCmd = New OleDbCommand("SELECT * FROM Content where ministryID=5", objConn)
      objRdr = objCmd.ExecuteReader()
      While objRdr.Read()
            intro.text = ("Intro: " & objRdr.Item("intro") & "<br />")
            content.text = ("Content: " & objRdr.Item("content") & "<br />")
      End While
      objRdr.Close()
      objConn.Close()
End Sub
0
GavinMannionCommented:
Did you get it working? Sorry I cannot tell when you accepted my post and when you posted this comment?

It looks like your SQL query is complaining... Possibly not an integer in the database?
0
azyet24Author Commented:
Yes I got it to work.  I had ministryID as text int he db but was assigning it to an integer.  After I changed that it worked fine.  Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.