Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 20th, 2003, 03:47 PM
Authorized User
 
Join Date: Oct 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Assigning DataSet data to variables

I'm building an ASP.NET intranet application. I have a table that stores a range of Bill of Lading numbers each day (say 1-10). I want to pull in the range of BOLs based on the max(date) and assign them to a variable. That way, the BOLs in the dataset become the beginning numbers for the new day, and the user just has to input the ending BOLs for that day. Question is, how can I assign the DataSet to a variable (array) that, in turn, can be re-used in an INSERT statement? I know this is a combo SQL/ASP.NET question, but I'm really concerned with the variable assignment, not the INSERT statement.

Here's my code, note the use of the Datagrid was for my visual purposes.

<script language = "VB" runat="server">
sub Page_Load(sender as Object, e as EventArgs)
    dim cnn as sqlconnection = new sqlconnection("server=blah;")
        try

        cnn.open()
        dim comm as sqlDataAdapter = New SqlDataAdapter ("SELECT [225_ENDING_BOL],[235_ENDING_BOL],[260_ENDING_BOL],[302_ENDING_BOL],[306_ENDING_BOL],[310_ENDING_BOL],[314_ENDING_BOL], [318_ENDING_BOL], [322_ENDING_BOL], [326_ENDING_BOL], [334_ENDING_BOL] FROM KM_BOL_RANGE WHERE lifted_date=(select max(lifted_date) from dbo.km_bol_range)", cnn)
        dim DS as new DataSet
        comm.fill(DS,"BOL")
        DataGrid1.DataSource=DS.Tables("BOL").DefaultView
        DataGrid1.Databind()

            catch ex as SqlException
            Status.Text = ex.Message

                Finally
                cnn.close()
        end try
End Sub
</script>

 
Old November 20th, 2003, 04:15 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It seems this task may better suit the use of the SqlDataReader and SqlCommand object. If you used the SqlDataReader object then you could use the SqlDataReader.GetValues() method which returns an array of objects, one for each column in the result set. This sounds like exactly what you are looking for.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 20th, 2003, 05:03 PM
Authorized User
 
Join Date: Oct 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Peter, you seem to always answer my questions. But I was just thinking, if I really just want to update the new row with yesterday's number plus today's number, could I use the DataTable/DataRow objects to push the data to the new row?

 
Old December 8th, 2003, 12:59 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

i think you could use datarow like this

        Dim SqlConnection1 As New SqlClient.SqlConnection(myConnectionString)
        Dim cmd As New SqlClient.SqlCommand()
        cmd.CommandText = "SELECT ProductID, ProductName,QuantityPerUnit FROM Products"
        cmd.CommandType = CommandType.Text
        cmd.Connection = SqlConnection1
        SqlConnection1.Open()

        Dim DA As New SqlClient.SqlDataAdapter()
        Dim dr As DataRow
        DA.SelectCommand = cmd
        DA.Fill(DS, "Products")
        dr = DS.Tables("Products").Rows.Item(certainIndex)
        txtQuantityPerUnit.Text = dr("QuantityPerUnit")
        txtProductName.Text = dr("ProductName")
        txtProductID.Text = dr("ProductID")

Ahmed Ali
Software Developer





Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning values to variables in Stored Procedures AlanAtMars SQL Server 2000 3 May 4th, 2005 12:37 AM
Assigning DataSet To Custom Server Control Raz Muhammad General .NET 0 November 29th, 2004 01:03 AM
filling Dataset with datagrid variables frankv25 ASP.NET 1.0 and 1.1 Professional 1 August 30th, 2004 01:05 PM
Assigning Session Variables morpheus Classic ASP Basics 2 November 21st, 2003 01:55 PM
Assigning Values to Variables shabboleth Beginning PHP 2 September 4th, 2003 07:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.