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