System.Data.DuplicateNameException in DataTable

I am dynamically adding columns to a static data table in! IsPostBack.

static DataTable dtflow = new DataTable();

protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            dtp.Columns.Add("slno");
            dtp.Columns.Add("portname");
            dtp.Columns.Add("type");
            dtp.Columns.Add("portid");
            dtp.Columns.Add("longitude");
            dtp.Columns.Add("latitude");
            dtp.Columns.Add("add1");
            dtp.Columns.Add("add2");
            dtp.Columns.Add("dist");
            dtp.Columns.Add("state");
            dtp.Columns.Add("country");
        }
    }

But when I launch my site a second time, it shows an exception like this

Exception Details: System.Data.DuplicateNameException: A column named 'slno' already belongs to this DataTable.

Can someone tell me how to solve this problem?

+5
source share
2 answers

A static datatable means that it will always be present regardless of the instances of your web pages. Therefore, when you start a web page for the first time, your Page_Load creates data, and all is well.

- , datatable , , datatable, .

3 :
1. . , .
2. if dtp.Columns.Adds, , . , , bool , .

3. , , datatable, . , , , datatable .

+2

static ASP.NET () , , , DataTable. .

, .

(, Session, ViewState ..).

ASP.NET

. , , . , . webdataound, GridView, ViewState. .

+3

All Articles