Wrox Programmer Forums
|
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 June 10th, 2005, 11:26 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default add new row to excel file

I was wondering if anyone knew how to add a row to a excel file. My code is a loop in which I display results in different rows. The problem is that I don't know how to display mutiple results. I am only capable of displaying the last record in my loop. I want to be able to create a new row in my loop for each of my records. An example of my code is as follows:

do while dr.read()
field1.text = dr.getfile(0)
field2.text = dr.getfile(1)
field3.text = dr.getfile(2)
loop

I would appreciate any help. Thank you.

 
Old June 10th, 2005, 11:53 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Are you sure you have more than one row in your result set? Is your loop logic correct? Maybe you can post more of your code for us to look at.

 
Old June 10th, 2005, 12:06 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sure I have more than one row in my result because I tested the statement out in Query Analyzer and I should have ten. Yet, it is only displaying the last one because it's looping. Here is what I have:

sqlstring = sqlstring & " and a.filenumber in(121632,172041703)"
        Dim comm3 As New SqlClient.SqlCommand(sqlstring, SqlConnection1)
        Dim dr3 As SqlClient.SqlDataReader

        Try
            SqlConnection1.Open()
            dr3 = comm3.ExecuteReader

            Do While dr3.Read()
                Response.Write("<tr>")
                fld1.Text = dr3.GetValue(0)
                fld2.Text = dr3.GetValue(1)
                fld3.Text = dr3.GetValue(2)
                fld4.Text = dr3.GetValue(3)
                fld5.Text = dr3.GetValue(4)
                Response.Write("</tr>")
            Loop

        Catch ex As Exception
        Finally
            dr3.Close()
            SqlConnection1.Close()
        End Try

I tried adding a row by putting the response.write. But, that didn't work. Is there any other way?

 
Old June 10th, 2005, 12:52 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I think the problem may be that you are using the GetValue method. This returns an object not the value of the column. You need to try the GetString() method.

 
Old June 10th, 2005, 01:08 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, it does return the value of the column. It reads it in fine. All I want to do is add a new row each time a record is read. Is there a way to do that?

 
Old June 10th, 2005, 01:59 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Your code should be working correctly. Check some examples in VS help or GOOGLE datareader. From what I see, your code is correct. Maybe you can post all the page code.

 
Old June 10th, 2005, 02:16 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is working. But, I just want it to create another row, which isn't part of the code. Can you tell me how to do that?

 
Old June 10th, 2005, 02:16 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you try it and tell me if it creates mutiple rows for you?

 
Old June 10th, 2005, 02:20 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

What do you mean by create another row? Do you mean a blank row?

 
Old June 10th, 2005, 02:22 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I mean create a blank row. I took out the response.write statement since it doesn't work.






Similar Threads
Thread Thread Starter Forum Replies Last Post
add row with textboxes in a table imnk2 ASP.NET 1.0 and 1.1 Basics 1 June 25th, 2007 04:53 PM
add new row to a table stealthdevil Access VBA 1 June 1st, 2006 11:04 AM
use vba to add a row to datasheet TerryAutomation Access VBA 2 July 11th, 2005 01:07 PM
import excel file and stop at first empty row derik SQL Server DTS 2 September 24th, 2004 04:16 AM
add row no automatically Jane SQL Language 9 June 28th, 2004 02:11 AM





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