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

Discussion in 'ASP .Net' started by Phil, Jan 4, 2010.

  1. Phil

    Phil Guest

    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
     
    Phil, Jan 4, 2010
    #1
    1. Advertising

  2. "Phil" <> wrote in
    news:#Zpu$:

    > 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! |
    *******************************************
     
    Gregory A. Beamer, Jan 4, 2010
    #2
    1. Advertising

  3. Phil

    Phil Guest

    ok, thanks
    "Gregory A. Beamer" <> schreef in bericht
    news:Xns9CF68327CE269gbworld@207.46.248.16...
    > "Phil" <> wrote in
    > news:#Zpu$:
    >
    >> 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! |
    > *******************************************
     
    Phil, Jan 4, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Denon
    Replies:
    1
    Views:
    603
    Saravana [MVP]
    Nov 14, 2003
  2. fniles
    Replies:
    6
    Views:
    684
    Karl E. Peterson
    Apr 27, 2009
  3. Iñaki Baz Castillo
    Replies:
    7
    Views:
    946
    Iñaki Baz Castillo
    Jan 12, 2010
  4. Iulian Ilea
    Replies:
    1
    Views:
    346
    pcx99
    Dec 21, 2006
  5. Replies:
    0
    Views:
    547
Loading...

Share This Page