Attempting to Export to Excel..."Class 'System.Data.DataSet' cannot be indexed"?

  • Thread starter Thread starter D. Shane Fowlkes
  • Start date Start date
D

D. Shane Fowlkes

Hello all.

I'm following the example found at
http://mikepope.com/blog/DisplayBlog.aspx?permalink=344 in an attempt to
export to MS Excel. I'm getting a "Class 'System.Data.DataSet' cannot be
indexed because it has no default property." error whenever I try to read
the DataSet I've attempted to create. Although, I've made a few
modifications from the example at the link above, I can't seem to figure out
why it won't work. Any help would greatly be appreciated.

Thanks!



<%@ Page Language="VB" Debug="true" EnableViewState="False" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>

<script runat="server">
Sub Page_Load()

Dim dsProjData As Dataset = GetData()
Dim drRow As DataRow
Dim strHTML As String

strHTML = "<table class=" & CHR(34) & "caption" & CHR(34) & "
cellspacing=" ....etc....rest of HTML for <table>....

For Each drRow In dsProjData.Tables(0).Rows

strHTML = strHTML & "<tr valign=" & CHR(34) & "top" & CHR(34) & ">" &
vbcrlf & _
"<td>" & Server.HtmlEncode(dsProjData("CostCodeDescription")) &
"</td>" & vbcrlf _
"<td>" & Server.HtmlEncode(dsProjData("ProjTask")) & "</td>" & vbcrlf
_
"<td>" & Server.HtmlEncode(dsProjData("FiscalYear")) & "</td>" &
vbcrlf _
.....etc...filling cells.......
"<td>" & Server.HtmlEncode(dsProjData("Notes")) & "</td>" & vbcrlf _
"</tr>" & vbcrlf

Next

strHTML = strHTML & "</table>"

lblProjectData.Text = strHTML

Response.ContentType = "application/vnd.ms-excel"

End Sub

'###########################################################

Function GetData() As System.Data.DataSet

Dim conSQLServer As SQLConnection
Dim cmdGetData As SQLCommand
Dim objAdapter As SQLDataAdapter
Dim strConnectString As String
Dim strSQL As String
Dim dsProjData As DataSet

conSQLServer = New SQLConnection
cmdGetData = New SQLCommand
objAdapter = New SQLDataAdapter
dsProjData = New System.Data.DataSet

strConnectString = ".......connection string....."
strSQL = "...big freaking SQL Select Statement..."

conSQLServer.ConnectionString = strConnectString

cmdGetData.CommandText = strSQL
cmdGetData.Connection = conSQLServer
objAdapter.SelectCommand = cmdGetData
objAdapter.SelectCommand.Connection.Open

objAdapter.Fill(dsProjData,"Projects")

Return dsProjData

conSQLServer.Close()

End Function
</script>


<html>
<head>
<link href="../../assets/css/intranet.css" rel="stylesheet" type="text/css"
/>
</head>
<body>
<form runat="server">
<asp:label id="lblProjectData" runat="server" />
</form>
</body>
</html>
 
You used dsProjData("CostCodeDescription") instead of
drRow("CostCodeDescription") and so on...

Patrice
 
Back
Top