 |
| 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
|
|
|
|

June 10th, 2005, 11:26 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

June 10th, 2005, 11:53 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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.
|
|

June 10th, 2005, 12:06 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

June 10th, 2005, 12:52 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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.
|
|

June 10th, 2005, 01:08 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

June 10th, 2005, 01:59 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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.
|
|

June 10th, 2005, 02:16 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

June 10th, 2005, 02:16 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can you try it and tell me if it creates mutiple rows for you?
|
|

June 10th, 2005, 02:20 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
What do you mean by create another row? Do you mean a blank row?
|
|

June 10th, 2005, 02:22 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, I mean create a blank row. I took out the response.write statement since it doesn't work.
|
|
 |