Results 1 to 3 of 3

Thread: ASP.NET Newbie Problem...

  1. #1
    Join Date
    May 2003

    ASP.NET Newbie Problem...

    With the ASP.NET Web matrix Project, I'm working through the example code for Sams "Teach Yourself ASP.NET in 24 Hours", but I'm running into an error that I can't solve. For the "Allowing the User to Decide What Customer's Information to View" section of the book's Chapter 16, I typed the following code:
    <%@ Page Language="VB" %>
    <script runat="server">
        Function faqs() As System.Data.DataSet
            Dim connectionString As String = "server='SERVERNAME'; user id='UN'; password='PW'; database='DBNAME'"
            Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
            Dim queryString As String = "SELECT * FROM [FAQ]"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection
            Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
            dataAdapter.SelectCommand = dbCommand
            Dim dataSet As System.Data.DataSet = New System.Data.DataSet
            Return dataSet
        End Function
        Sub btnView_Click(sender As Object, e As EventArgs)
            dgfaqs.DataSource = faqs(FAQID.Text)
            If dgfaqs.Items.Count = 0 then
                lblNoRecords.Visible = True
                lblNoRecords.Visible = False
            End If
        End Sub
        <form runat="server">
                FAQ ID: 
                <asp:TextBox id="FAQID" runat="server" Columns="3" MaxLength="3" OnTextChanged="FAQID_TextChanged"></asp:TextBox>
                <asp:Button id="btnView" onclick="btnView_Click" runat="server" Text="View Customer"></asp:Button>
                <asp:DataGrid id="dgfaqs" runat="server" AutoGenerateColumns="False">
                    <AlternatingItemStyle font-size="10pt" font-names="Arial" backcolor="#FFFFCC"></AlternatingItemStyle>
                    <ItemStyle font-size="10pt" font-names="Arial"></ItemStyle>
                    <HeaderStyle font-size="12pt" font-names="Arial" font-bold="True" horizontalalign="Center" forecolor="White" backcolor="Navy"></HeaderStyle>
                        <asp:BoundColumn DataField="FAQ_ID" HeaderText="ID"></asp:BoundColumn>
                        <asp:BoundColumn DataField="Question" HeaderText="Questions"></asp:BoundColumn>
                        <asp:BoundColumn DataField="Answer" HeaderText="Answers"></asp:BoundColumn>
                <asp:Label id="lblNoRecords" runat="server" font-bold="True">There were no records</asp:Label>
            <!-- Insert content here -->
    ...but this code results in this error message:
    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30367: Class 'System.Data.DataSet' cannot be indexed because it has no default property.

    Source Error:

    Line 20:
    Line 21: Sub btnView_Click(sender As Object, e As EventArgs)
    Line 22: dgfaqs.DataSource = faqs(FAQID.Text)
    Line 23: dgfaqs.DataBind()
    Line 24:

    Source File: E:\wwwroot\dgcowww\test_folder\aspx\test pages\test.aspx Line: 22
    I've tried looking up that error, but I've still not come up a solution. If someone can let me know what I'm doing wrong, and how I can fix it, it would be greatly appreciated. Thanks.
    It's the end of the world as we know it...and I feel fine

  2. #2
    Join Date
    Nov 2003
    faqs(FAQID.Text) is the problem.

    It thinks you're trying to assign FAQID.Text to the default property of the dataset returned by faqs. There is no default property for a dataset.
    Last edited by CardboardHammer; 11-22-2004 at 12:49 PM.

  3. #3
    Join Date
    Nov 2004
    CardboardHammer is right. You have the function faqs() as DataSet and you are trying to pass a parameter to the function, and because there is no parameter in your function, it is trying to index the DataSet and find the element in there.

    You should modify the function faqs() to have a parameter so that you can use it as a parameter to your SELECT statement and return your data.

    Ben Miller
    All responses are provided AS IS and do not necessarily reflect my employers views.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center