Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

field value is not showing up

Status
Not open for further replies.

kebele

MIS
Joined
Jul 31, 2006
Messages
107
Location
US
hi all,
I am using the below code to create a page where users can see the information and also i create a link for them to download a CSv format file.Everyting works fine except when i open the link to download the CSV file, I just only see the Column name not the values.It just only display the column name.I would appreciate if you point me where i made the mistake and how can i fix it. thanks again


<Script runat="server" language="VB">

Dim cmdc As OracleCommand
Dim drc As OracleDataReader
Dim oOracleConn As OracleConnection
Dim i As Integer
Dim filename As String
Dim sb As System.Text.StringBuilder
Dim StrSql As String

Sub page_load()
lblTime.Text = DateTime.Now.ToString()
Dim connectionString As String = ConnectionStrings("ConnectionString").ConnectionString
Dim oOracleConn As OracleConnection = New OracleConnection(connectionString)
oOracleConn.Open()

StrSql = "SELECT (SUBSTR( ITEM ,1,4)||'.'||SUBSTR(ITEM,5)) ""ITEM NUMBER"","
StrSql = StrSql & "IDESCR ""SHORT DESCRIPTION"", "
StrSql = StrSql & "IDESCRL ""LONG DESCRIPTION"", "
StrSql = StrSql & "IUNITS ""UNIT NAME"", FUNC_GET_UNIT_NAME(IUNITS) ""PLAN UNIT DESCRIPTION"""
StrSql = StrSql & "FROM ITEMLIST WHERE ISPECYR='01' AND IOBSELET='N' AND ITEM <> '2999509/00001'"

Dim cmd As OracleCommand = New OracleCommand(StrSql, oOracleConn)
drc = cmd.ExecuteReader()
gvEnglish.DataSource = drc
gvEnglish.DataBind()
filename = "MetricItemList.csv"
sb = New System.Text.StringBuilder

'Dim cmdc As OracleCommand = New OracleCommand(StrSql, oOracleConn)
'drc = cmdc.ExecuteReader()
End Sub

Sub Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

'for field name
For i = 0 To drc.FieldCount - 1
If i < (drc.FieldCount - 1) Then
sb.Append(Chr(34) & drc.GetName(i) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drc.GetName(i) & Chr(34) & vbCrLf)
End If
Next

''for field value
While drc.Read()
For i = 0 To drc.FieldCount - 1
If i < (drc.FieldCount - 1) Then
sb.Append(Chr(34) & drc.GetValue(i).ToString.Replace(Chr(34), Chr(34) & Chr(34)) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drc.GetValue(i).ToString & Chr(34) & vbCrLf)
End If
Next
End While

drc.Close()
Response.ContentType = "Application/x-csv"
Response.AddHeader("content-disposition", "attachment;filename=""" & filename & """")
Response.Write(sb.ToString)
Response.End()

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top