JoJo
JoJo

Reputation: 4933

Where is the DataTable Data? Does it clear on the return?

I have a method that populates a DataTable. It is doing that fine. I made the variable Public so I could use it again.

When I go to use the data later on the Save method the DataTable no longer shows any rows.

How do I persist the DataTable better?

    public DataTable dtHeadCats = new DataTable();
protected DataTable GetContentHeaders()
{
    using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ToString()))
    {
        using (SqlCommand cmdHeaderCats = cn.CreateCommand())
        {
            SqlDataAdapter sdaCtats = new SqlDataAdapter(cmdHeaderCats);

            cmdHeaderCats.CommandText = "uspGetData";
            cmdHeaderCats.CommandType = CommandType.StoredProcedure;
            cn.Open();
            sdaCtats.Fill(dtHeadCats);
            cn.Close();
        }
    }
    return dtHeadCats;
}

protected void multiFileUpload_FileUploaded(object sender, FileUploadedEventArgs e)
{
    // various logic... but the dtHeadCats is now empty..
    DataView dview = new DataView(dtHeadCats);
}

Upvotes: 0

Views: 43

Answers (1)

Vladimirs
Vladimirs

Reputation: 8609

Seems issue is that you are not persisting state of dtHeadCats between your post backs. Try store that in Session.

Upvotes: 3

Related Questions