Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Really Simple Question
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Really Simple Question

 Post Reply Post Reply Page  12>
Author
BigMeat View Drop Down
Newbie
Newbie


Joined: 29 May 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote BigMeat Quote  Post ReplyReply Direct Link To This Post Topic: Really Simple Question
    Posted: 03 June 2003 at 4:37am

Hi

I have  a really simple question (hoppefully), I have created a details page that uses a dataset.  So the dataset is only ever filled with one row of data.  I want to put the dataset values into variouse labels on the  page.  But Im not sure of the syntaxt to display a record from a dataset.  Here is a piece of my code:

Dim Conn As New SqlConnection(ConfigurationSettings.AppSettings("connBSS"))
Conn.Open()
Dim dsDetails As New DataSet()
Dim strSQL As String = "SELECT SvpsName, SvpsID FROM Services"
Dim objAdapter As New SqlDataAdapter(strSQL, Conn)
objAdapter.Fill(dsDetails, "Details")
Dim objDataView As New DataView(dsDetails.Tables("Details"))

I thought I could display display a value by doing something like:

lblSvpsName.text = DataBinder.Eval(objDataView, "SvpsName")

But it didnt work, as you can tell I am new to this ASP.NET, thanks in advance

 

 

 

Back to Top
otaku View Drop Down
Newbie
Newbie


Joined: 01 June 2003
Location: Canada
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote otaku Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2003 at 6:17am

Hi BigMeat,

You don't need to open your connection or even close it.
The Fill method retrieves rows from the data source using the SELECT
statement specified by an associated SelectCommand property.
The connection object associated with the SELECT statement must be valid,
but it does not need to be open. If the connection is closed before Fill
is called, it is opened to retrieve data, then closed. If the connection
is open before Fill is called, it remains open.

Also, I don't think you need any DataView. To get only the first row use this:

dsDetails.Tables("Details").Rows(0).Item("SvpsName")


Something like this:


Dim dsDetails As New DataSet()
Dim Conn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("connBSS"))
Dim objAdapter As SqlDataAdapter = New SqlDataAdapter("SELECT SvpsName, SvpsID FROM Services", Conn)

objAdapter.Fill(dsDetails, "Details")

lblSvpsName.Text = dsDetails.Tables("Details").Rows(0).Item("SvpsName")
lblSvpsID.Text = dsDetails.Tables("Details").Rows(0).Item("SvpsID")

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2003 at 8:32am

i dont even know why you would use a dataset in that situation...

could just use a SQLDataReader as reference it like school recordset-like.. one less object to create :-)

Contribute to the working anarchy we fondly call the Internet
Back to Top
otaku View Drop Down
Newbie
Newbie


Joined: 01 June 2003
Location: Canada
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote otaku Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2003 at 9:29am

Whenever you have a one-time hit of data from a database, use a DataReader,
it's much faster than a DataSet. Dataset uses a DataReader to get its data anyway.

If you are requesting data that is going to be used or accessed multiple times,
use the DataSet. It grabs the data from the table, puts it in memory and then
closes the connection.

DataReader can't as it is read-only, forward only so if you need same data twice,
with DataReader you'd have recreate the DataReader every time data is reused,
with DataSet you have the data to be used as many times you like.

Back to Top
BigMeat View Drop Down
Newbie
Newbie


Joined: 29 May 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote BigMeat Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2003 at 9:41am

Cheers Otaku

You are a star.... i really appreciate all your help

Back to Top
BigMeat View Drop Down
Newbie
Newbie


Joined: 29 May 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote BigMeat Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2003 at 9:45am

The reason I used a dataset is because the above example does not show the full sql statement I used, the real one pulls values from two tables.  Which I dont think is possible form a datareader (dont hold me to that as I new to all of this)

But I might aswell ask.... can I join two tables and still use the read method?

Thanks in advance

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2003 at 10:16am
nothing's stopping you from using a JOIN, UNION, etc in the SQL statement
Contribute to the working anarchy we fondly call the Internet
Back to Top
BigMeat View Drop Down
Newbie
Newbie


Joined: 29 May 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote BigMeat Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2003 at 11:19am

Im really sorry to be a pain, but I have just come accross another problem with my first application.  The website works perfectly fine on my development machine.  However if any body else tries to view it from there machine they get an error saying:

"An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine."

However I have noticed that this error only occurs on pages that are datadriven from a database.  


I have the following security settings:

<add key="connBSS" value="Password=BSS_WClient;Persist Security Info=False;User ID=BSS_WClient;Initial Catalog=BSS;Data Source=bsswk1" />

<identity impersonate="true"/>
<customErrors mode="RemoteOnly"/>
<authentication mode="Windows"/> tried None aswell but didnt work
<allow users="*"/>

I cant really understand why this happens?  Is it a sql server problem?  Sorry to be a pain... but I will get use to this ASP.NET eventually

Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.