Hey. I'm pretty new to ASP.NET and coding it in VB. I'm working on some tutorials on how to view and edit data from a SQL Data Source. I'm using the GridView feature, but I'm getting some errors. The major one, is that it requires me to declare a scalar variable, while the code in the book has none, and after trying to fix it, I'm getting to new errors while compiling, so the web page wont even load. I've been searching for a fix, but I don't understand what I've been finding. I'm including the code I have, and the two compiling errors I'm getting. Thanks for the help.

-Jesse

<%@ Page Debug="true" Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebMatrix.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Sub On_Click(ByVal source As Object, ByVal e As EventArgs)
        SqlDataSource1.Update()
    End Sub 'On_Click 
    </script>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
        AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" 
        EmptyDataText="There are no data records to display.">
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" 
                SortExpression="ID" />
            <asp:BoundField DataField="lName" HeaderText="lName" 
                SortExpression="lName" />
            <asp:BoundField DataField="fName" HeaderText="fName" 
                SortExpression="fName" />
            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
            <asp:BoundField DataField="Zip Code" HeaderText="Zip Code" 
                SortExpression="Zip Code" />
        </Columns>
    </asp:GridView>
   
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
        SelectCommand="SELECT ID, lName, fName, City, State, [Zip Code] FROM InfoTester" 
        UpdateCommand="UPDATE InfoTester SET fName = @fName WHERE lName = 'Jobs'">
        <UpdateParameters>
        <asp:ControlParameter Name="LastName" ControlID="DropDownList1" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="fName" ControlID="GridView1" PropertyName="SelectedValue" />
        </UpdateParameters>
        
    </asp:SqlDataSource>
    <p>
        <asp:DropDownList id="DropDownList1" runat="server" DataTextField="lName" DataValueField="lName" DataSourceID="SqlDataSource1"></asp:DropDownList>
        
        <asp:Label ID="Label1" runat="server" Text="Enter the new First Name" AssociatedControlID = "TextBox1" />
        <asp:TextBox 
            ID="TextBox1" runat="server" style="margin-left: 17px" Width="110px"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" 
            style="margin-left: 17px; margin-bottom: 0px" Text="Enter" 
            OnClick="On_Click" Width="45px" />
        
    </p>
    <p>
        Type the new First Name of the person below. Click enter to see if I know what 
        I'm doing.</p>
    <asp:TextBox ID="TextBox2" runat="server" Width="198px"></asp:TextBox>
    </form>
</body>
</html>

Here's the compiling errors:
Error 1 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. F:\WebMatrix\03B_fanbiopretty\web.config 86


Warning 2 F:\WebMatrix\WebMatrix\WebMatrix\Default.aspx: ASP.NET runtime error: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. (F:\WebMatrix\webmatrix\webmatrix\web.config line 84) F:\WebMatrix\WebMatrix\WebMatrix\Default.aspx 1 1 F:\WebMatrix\

Recommended Answers

All 2 Replies

The errors are both related to IIS configuration you need configure the application virtual directories as applications:

http://msdn.microsoft.com/en-us/library/zwk103ab.aspx

If you are using shared hosting you will need to ask the hosting company to configure it for you, or some hosting companies allow you to do it yourself via their control panel.

Your Subject is Misleading.

How did you deploy your Application. Please Explain step by Step , because if you have missed one simple step it will give you errors.

I dont use Wizards to do my database work, i can see that you have used a sqldatasource Control and really you dont have control over what is generated by the control. if you get an error that says you must declare scalar variable , you must know that one of the Variables in the Sql like @fName, am not sure how it works because i dont use it.

Hope i helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.