Error on gridView code

I am trying to return the results of a table to a webpage
using aspx and aspx.cs c#
front code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" />

Open in new window

back end code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
    private const string MDBFILE = "FileUpload2.mdb";
    protected System.Web.UI.WebControls.GridView;

    private string GetConnectionString()
            return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(MDBFILE) + ";";

    protected void Page_Load(object sender, EventArgs e)
        string SQL = "SELECT * FROM FSUdata ";

        // Create Connection object
        OleDbConnection dbConn = new OleDbConnection(GetConnectionString());

        // Create Command Object
        OleDbCommand dbComm = new OleDbCommand(SQL, dbConn);

        // Open Connection

        // Execute command and receive DataReader
        OleDbDataReader dbRead = dbComm.ExecuteReader();

        GridView1.DataSource = dbRead;



Open in new window

Compiler Error Message: CS1519: Invalid token ';' in class, struct, or interface member declaration

Source Error:

Line 13: {
Line 14:     private const string MDBFILE = "FileUpload2.mdb";
Line 15:     protected System.Web.UI.WebControls.GridView;
Line 16:
Line 17:

Who is Participating?
Easwaran ParamasivamConnect With a Mentor Commented:
protected System.Web.UI.WebControls.GridView;

 Above code should be changed as

 protected System.Web.UI.WebControls.GridView GridView1;

Easwaran ParamasivamCommented:
In your ASPX page set AutoGenerateColumns="true" for the Gridview control. Look at the example at
TagomAuthor Commented:
I made the correction suggested, good catch - thank you.
However I still get the same error in the backend file.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.