Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Datareader help

Posted on 2006-04-18
7
Medium Priority
?
252 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:azyet24
  • 3
  • 3
7 Comments
 
LVL 15

Accepted Solution

by:
GavinMannion earned 2000 total points
ID: 16477427
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
 
LVL 7

Expert Comment

by:brdrok
ID: 16477651
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
 

Author Comment

by:azyet24
ID: 16477745
Is it better to use a literal or placeholder?  Or is there a better way?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:GavinMannion
ID: 16477789
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
 

Author Comment

by:azyet24
ID: 16479318
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
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16481121
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
 

Author Comment

by:azyet24
ID: 16482222
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question