how to write updated list to excel without having to close the browser first?

P

Phil

Hi,

this code writes a single line to an excel sheet followed by a list of names
coming from a table in the database. The table is chosen from a
dropdownlist.
This works properly.
My problem is: suppose i wrote all the names of a table to excel. Then i
return to the main menu of the application without closing the browser.
Suppose now that the same table with the names is updated (e.g. by another
user who adds some new names). If i start this code below again and then
opening the new excel sheet (or first saving on my desktop), i see exactly
the same names as the previous time, with other words, the new names are not
sent to excel.
In order to see the new names in excel, i have to close the browser and then
restarting it. Even a refresh of the page doesn't help.

Is there no way to get the updated list without having to close the browser
first?
Thanks for help.
Phil

Here the code (vb.net)

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
Dim selectedval As String
Dim strLine, filename As String
Dim connection As SqlConnection
Dim dr As SqlDataReader

Dim objFileStream As FileStream
Dim objStreamWriter As StreamWriter

selectedval = DropDownList1.SelectedValue

fileName = "test.xls"
If File.Exists(fileName) Then File.Delete(fileName)

objFileStream = New FileStream(fileName, FileMode.OpenOrCreate,
FileAccess.Write)
objStreamWriter = New StreamWriter(objFileStream)
objStreamWriter.WriteLine("This is sent to an excel sheet")

connection.Open()
Dim sql As String = "SELECT name FROM " & selectedvalue
Dim cmd As SqlCommand = New SqlCommand(sql, connection)
dr = cmd.ExecuteReader()

While dr.Read()
strLine = strLine & dr.GetString(0) & Chr(9)
objStreamWriter.WriteLine(strLine)
strLine = ""
End While

dr.Close()
connection.Close()
objStreamWriter.Close()
objFileStream.Close()
End Sub
 
G

Gregory A. Beamer

Is there no way to get the updated list without having to close the
browser first?

You have to determine if this is a serious problem or not. How likely is
it going to be that someone adds a new item to the dropdown and someone
already in session is going to have to use it? If "never" then this is
not an issue to spend much time on. Same with "not very often".

Many times we see development problems as production problems, so think
how important it is to "solve" this issue before burning a lot of
cycles.

Having said that, there is little you can do to control a user's browser
cache, unless they are part of a business and you can dictate browser
policy. You can expire the page sooner, which will force it to either
bomb or get the newer bits, but that is about all you can do if the
browser is set with default caching policies.

Personally, I would not use Excel as a data store, as I don't think it
is the proper direction to head, but that is another issue.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
P

Phil

ok, thanks
Gregory A. Beamer said:
You have to determine if this is a serious problem or not. How likely is
it going to be that someone adds a new item to the dropdown and someone
already in session is going to have to use it? If "never" then this is
not an issue to spend much time on. Same with "not very often".

Many times we see development problems as production problems, so think
how important it is to "solve" this issue before burning a lot of
cycles.

Having said that, there is little you can do to control a user's browser
cache, unless they are part of a business and you can dictate browser
policy. You can expire the page sooner, which will force it to either
bomb or get the newer bits, but that is about all you can do if the
browser is set with default caching policies.

Personally, I would not use Excel as a data store, as I don't think it
is the proper direction to head, but that is another issue.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top