Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Referencing Individual Data Columns


Message #1 by "Hugh McLaughlin" <hugh@k...> on Thu, 7 Mar 2002 11:23:54
Hello everyone and thanks for your help in advance.  I am currently 

working with a SQL Server table and want to be able to execute a query 

that returns data from one column in the table.  I am using a DataSet to 

access the table.  What I want to do is to set a variable equal to the 

value in that table, for example in classic ASP



strFirstName=rstemp("FirstName")



I can't seem to figure out how to do this since most examples imply push 

the dataset into a datagrid for display.  Not entirely sure that the 

dataset is even the best method.  Any help would be greatly appreciated.  

Thanks.
Message #2 by "Lewis" <lewis@t...> on Thu, 7 Mar 2002 05:34:51 -0700
Data sets can be wonderful animals but they do tend to "distance" the

developer from the data

you need to use a dataview or some very complicated logic. I have found that

the dataview is usually easier to work with



however here is a block of code that would not require a dataview - and

might work for you



Dim qry As String

Dim dsgrid As DataSet



qry = "select tapes_tracking.* from tapes_tracking where

tapes_tracking.check_in_date is null " & _

            " order by tapes_tracking.check_out_date desc,

tapes_tracking.tracking_idx"

dsgrid = Get_DataSet(qry) ' this is a function that opens the database and

does all of the setup for a dataset

dgReport.DataSource = dsgrid.Tables("Data")

dgReport.DataBind()

' displays the total count of the rows

lblTotal.Text = lblTotal.Text & " " & dsgrid.Tables("Data").Rows.Count

dsgrid.Dispose()



the code above displays the total number of rows in the dataset

you could probably acces the actual rows with something similiar to

dim str as string

dsgrid.tables("data").rows(0)("fieldname")



but i would suggest something like below

dim dv as dataview

dv = dsgrid.tables("data")

str = dv(0)("fieldname")



hope this helps.





-----Original Message-----

From: Hugh McLaughlin [mailto:hugh@k...]

Sent: Thursday, March 07, 2002 11:24 AM

To: ASP+

Subject: [aspx] Referencing Individual Data Columns





Hello everyone and thanks for your help in advance.  I am currently

working with a SQL Server table and want to be able to execute a query

that returns data from one column in the table.  I am using a DataSet to

access the table.  What I want to do is to set a variable equal to the

value in that table, for example in classic ASP



strFirstName=rstemp("FirstName")



I can't seem to figure out how to do this since most examples imply push

the dataset into a datagrid for display.  Not entirely sure that the

dataset is even the best method.  Any help would be greatly appreciated.

Thanks.






Message #3 by "Hugh McLaughlin" <hugh@k...> on Thu, 7 Mar 2002 12:53:47
Thanks.  I had a hunch the dataset was a tough choice.  I appreciate your 

help.



> Data sets can be wonderful animals but they do tend to "distance" the

> developer from the data

> you need to use a dataview or some very complicated logic. I have found 

that

> the dataview is usually easier to work with

> 

> however here is a block of code that would not require a dataview - and

> might work for you

> 

> Dim qry As String

> Dim dsgrid As DataSet

> 

> qry = "select tapes_tracking.* from tapes_tracking where

> tapes_tracking.check_in_date is null " & _

>             " order by tapes_tracking.check_out_date desc,

> tapes_tracking.tracking_idx"

> dsgrid = Get_DataSet(qry) ' this is a function that opens the database 

and

> does all of the setup for a dataset

> dgReport.DataSource = dsgrid.Tables("Data")

> dgReport.DataBind()

> ' displays the total count of the rows

> lblTotal.Text = lblTotal.Text & " " & dsgrid.Tables("Data").Rows.Count

> dsgrid.Dispose()

> 

> the code above displays the total number of rows in the dataset

> you could probably acces the actual rows with something similiar to

> dim str as string

> dsgrid.tables("data").rows(0)("fieldname")

> 

> but i would suggest something like below

> dim dv as dataview

> dv = dsgrid.tables("data")

> str = dv(0)("fieldname")

> 

> hope this helps.

> 

> 

> -----Original Message-----

> From: Hugh McLaughlin [mailto:hugh@k...]

> Sent: Thursday, March 07, 2002 11:24 AM

> To: ASP+

> Subject: [aspx] Referencing Individual Data Columns

> 

> 

> Hello everyone and thanks for your help in advance.  I am currently

> working with a SQL Server table and want to be able to execute a query

> that returns data from one column in the table.  I am using a DataSet to

> access the table.  What I want to do is to set a variable equal to the

> value in that table, for example in classic ASP

> 

> strFirstName=rstemp("FirstName")

> 

> I can't seem to figure out how to do this since most examples imply push

> the dataset into a datagrid for display.  Not entirely sure that the

> dataset is even the best method.  Any help would be greatly appreciated.

> Thanks.




> 

Message #4 by Chad Coley <ccoley@b...> on Thu, 7 Mar 2002 09:28:13 -0700
I'm pretty much a newbie at this, but I was able to get it to work using the

DataReader. This might give you another option to investigate. Conversion to

VB should be pretty simple if you needed. Any feedback is very welcome.



//----------------------------------------------

int myID = Convert.ToInt32(Request.QueryString["ID"]);

string strSQL = "SELECT IDField, Title FROM myTable WHERE IDField = @ID";



SqlConnection myConnection = new

SqlConnection("server=(local);database=myDatabase;uid=username;password=pass

word");

myConnection.Open();

SqlCommand myCommand = new SqlCommand(strSQL, myConnection);

myCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int));

myCommand.Parameters["@ID"].Value = myID;



SqlDataReader myDataReader = myCommand.ExecuteReader();



try

{

	myDataReader.Read();

	txtMyID.Text = myDataReader["IDField"].ToString();

	txtTitle.Text = myDataReader["Title"].ToString();

}

catch (Exception eCatch)

{

	lblErrorMessage.Text = eCatch.Message;

}



myDataReader.Close();

myConnection.Close();

//----------------------------------------------



Hope this helps.



-----Original Message-----

From: Hugh McLaughlin [mailto:hugh@k...] 

Sent: Thursday, March 07, 2002 5:54 AM

To: ASP+

Subject: [aspx] RE: Referencing Individual Data Columns





Thanks.  I had a hunch the dataset was a tough choice.  I appreciate your 

help.



> Data sets can be wonderful animals but they do tend to "distance" the

> developer from the data

> you need to use a dataview or some very complicated logic. I have found 

that

> the dataview is usually easier to work with

> 

> however here is a block of code that would not require a dataview - and

> might work for you

> 

> Dim qry As String

> Dim dsgrid As DataSet

> 

> qry = "select tapes_tracking.* from tapes_tracking where

> tapes_tracking.check_in_date is null " & _

>             " order by tapes_tracking.check_out_date desc,

> tapes_tracking.tracking_idx"

> dsgrid = Get_DataSet(qry) ' this is a function that opens the database 

and

> does all of the setup for a dataset

> dgReport.DataSource = dsgrid.Tables("Data")

> dgReport.DataBind()

> ' displays the total count of the rows

> lblTotal.Text = lblTotal.Text & " " & dsgrid.Tables("Data").Rows.Count

> dsgrid.Dispose()

> 

> the code above displays the total number of rows in the dataset

> you could probably acces the actual rows with something similiar to

> dim str as string

> dsgrid.tables("data").rows(0)("fieldname")

> 

> but i would suggest something like below

> dim dv as dataview

> dv = dsgrid.tables("data")

> str = dv(0)("fieldname")

> 

> hope this helps.

> 

> 

> -----Original Message-----

> From: Hugh McLaughlin [mailto:hugh@k...]

> Sent: Thursday, March 07, 2002 11:24 AM

> To: ASP+

> Subject: [aspx] Referencing Individual Data Columns

> 

> 

> Hello everyone and thanks for your help in advance.  I am currently

> working with a SQL Server table and want to be able to execute a query

> that returns data from one column in the table.  I am using a DataSet to

> access the table.  What I want to do is to set a variable equal to the

> value in that table, for example in classic ASP

> 

> strFirstName=rstemp("FirstName")

> 

> I can't seem to figure out how to do this since most examples imply push

> the dataset into a datagrid for display.  Not entirely sure that the

> dataset is even the best method.  Any help would be greatly appreciated.

> Thanks.




> 






Message #5 by Chad Coley <ccoley@b...> on Thu, 7 Mar 2002 10:03:07 -0700
This message is in MIME format. Since your mail reader does not understand

this format, some or all of this message may not be legible.



------_=_NextPart_001_01C1C5F9.F3C88D60

Content-Type: text/plain



I'm pretty much a newbie at this, but I was able to get it to work using the

DataReader. This might give you another option to investigate. Conversion to

VB should be pretty simple if needed. Any feedback is very welcome.



//----------------------------------------------

int myID = Convert.ToInt32(Request.QueryString["ID"]);

string strSQL = "SELECT IDField, Title FROM myTable WHERE IDField = @ID";



SqlConnection myConnection = new

SqlConnection("server=(local);database=myDatabase;uid=username;password=pass

word");



myConnection.Open();

SqlCommand myCommand = new SqlCommand(strSQL, myConnection);

myCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int));

myCommand.Parameters["@ID"].Value = myID;



SqlDataReader myDataReader = myCommand.ExecuteReader();



try

{

	myDataReader.Read();

	txtMyID.Text = myDataReader["IDField"].ToString();

	txtTitle.Text = myDataReader["Title"].ToString();

}

catch (Exception eCatch)

{

	lblErrorMessage.Text = eCatch.Message;

}



myDataReader.Close();

myConnection.Close();

//----------------------------------------------



Hope this helps.



-----Original Message-----

From: Hugh McLaughlin [mailto:hugh@k...

<mailto:hugh@k...> ] 

Sent: Thursday, March 07, 2002 5:54 AM

To: ASP+

Subject: [aspx] RE: Referencing Individual Data Columns





Thanks.  I had a hunch the dataset was a tough choice.  I appreciate your 

help.



> Data sets can be wonderful animals but they do tend to "distance" the

> developer from the data

> you need to use a dataview or some very complicated logic. I have found 

that

> the dataview is usually easier to work with

> 

> however here is a block of code that would not require a dataview - and

> might work for you

> 

> Dim qry As String

> Dim dsgrid As DataSet

> 

> qry = "select tapes_tracking.* from tapes_tracking where

> tapes_tracking.check_in_date is null " & _

>             " order by tapes_tracking.check_out_date desc,

> tapes_tracking.tracking_idx"

> dsgrid = Get_DataSet(qry) ' this is a function that opens the database 

and

> does all of the setup for a dataset

> dgReport.DataSource = dsgrid.Tables("Data")

> dgReport.DataBind()

> ' displays the total count of the rows

> lblTotal.Text = lblTotal.Text & " " & dsgrid.Tables("Data").Rows.Count

> dsgrid.Dispose()

> 

> the code above displays the total number of rows in the dataset

> you could probably acces the actual rows with something similiar to

> dim str as string

> dsgrid.tables("data").rows(0)("fieldname")

> 

> but i would suggest something like below

> dim dv as dataview

> dv = dsgrid.tables("data")

> str = dv(0)("fieldname")

> 

> hope this helps.

> 

> 

> -----Original Message-----

> From: Hugh McLaughlin [mailto:hugh@k...

<mailto:hugh@k...> ]

> Sent: Thursday, March 07, 2002 11:24 AM

> To: ASP+

> Subject: [aspx] Referencing Individual Data Columns

> 

> 

> Hello everyone and thanks for your help in advance.  I am currently

> working with a SQL Server table and want to be able to execute a query

> that returns data from one column in the table.  I am using a DataSet to

> access the table.  What I want to do is to set a variable equal to the

> value in that table, for example in classic ASP

> 

> strFirstName=rstemp("FirstName")

> 

> I can't seem to figure out how to do this since most examples imply push

> the dataset into a datagrid for display.  Not entirely sure that the

> dataset is even the best method.  Any help would be greatly appreciated.

> Thanks.

> ---

> Change your mail options at http://p2p.wrox.com/manager.asp

<http://p2p.wrox.com/manager.asp>  or






  Return to Index