[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1391
  • Last Modified:

Details Column 'Name' does not belong to table .

Hi
In my code below I try to display the contents of a directory in a GridView but I get an error
Thanks


Method GetDataColumn
Details Column 'Name' does not belong to table .
Stack Trace System. Data. DataRow. GetDataColumn (String columnName)
System. Data. DataRow. set_Item (String columnName, Object value)
AnPostWebParts. AnPostMediaCoverageAdminWebPart. GetListOfWaitingDocuments()
AnPostWebParts. AnPostMediaCoverageAdminWebPart. OnWebPartPreRender()
AnPostWebParts. BaseClasses. BaseWebPart. OnPreRender (EventArgs e)  

protected override void OnWebPartPreRender()
        {

            //resultsGrid.Enabled = false;
            resultsGrid.DataSource = GetListOfWaitingDocuments();
            //resultsGrid.Enabled = true;
            resultsGrid.DataBind();


        }

        private DataView GetListOfWaitingDocuments()
        {

            //Get the directory specified by the user
            DirectoryInfo dirCustom = new DirectoryInfo(waitingFolder);

            // We'll store the file list here
            FileInfo[] filCustom;

            filCustom = dirCustom.GetFiles("*.xml");

            DataView myDataView = default(DataView);
            DataTable waitingDocuments = new DataTable();
            DataRow myDataRow = default(DataRow);

            // Loop through the file list
            foreach (FileInfo theFile in filCustom)
            {
                myDataRow = waitingDocuments.NewRow();

                myDataRow["Name"] = theFile.Name;
                myDataRow["Length"] = theFile.Length;
                myDataRow["LastWriteTime"] = theFile.LastWriteTime;
                myDataRow["Extension"] = theFile.Extension;
                waitingDocuments.Rows.Add(myDataRow); 
            }

            
            myDataView = waitingDocuments.DefaultView;
            return myDataView;
            
        }

        // ASP.NET controls
        Label headingLabel;
        GridView resultsGrid;

Open in new window

0
hmcgeehan
Asked:
hmcgeehan
  • 5
  • 4
  • 2
  • +3
1 Solution
 
princeatapiCommented:
are u sure  that the field "Name" available in DataRow  myDataRow  ?
0
 
Maheshwar RSoftware DeveloperCommented:
in the result grid manually  put the colomns names as "Name" ,"Length","LastWriteTime","Extension".. and manually bind to datafield for the respected colomns..
0
 
anvCommented:
provide the XML that you are using.
Also, try to travers through all the columns of the datatable to check what ngames are given to all the columns.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
hmcgeehanAuthor Commented:
"in the result grid manually  put the colomns names as "Name" ,"Length","LastWriteTime","Extension".. and manually bind to datafield for the respected colomns.."

How do I do that?
Thanks
0
 
madhevan_pillaiCommented:
    DataView myDataView = default( DataView);
     DataTable waitingDocuments = new DataTable();
     waitingDocuments.Columns.Add("Name");
     waitingDocuments.Columns.Add("Length");
     waitingDocuments.Columns.Add("LastWriteTime");
     waitingDocuments.Columns.Add("Extension");
     DataRow myDataRow = default(DataRow);

     // Loop through the file list
     foreach (FileInfo theFile in filCustom)
     {
         myDataRow = waitingDocuments.NewRow();

         myDataRow["Name"] = theFile.Name;
         myDataRow["Length"] = theFile.Length;
         myDataRow["LastWriteTime"] = theFile.LastWriteTime;
         myDataRow["Extension"] = theFile.Extension;
         waitingDocuments.Rows.Add(myDataRow);
     }
0
 
Maheshwar RSoftware DeveloperCommented:
click on ResultGrid and in the proerties click on the colomns.. in colomns add a bound field give it a name in the HeaderText Field and in the dataFiels give the "Name" respectively..
0
 
hmcgeehanAuthor Commented:
Now it says ...

Method OnWebPartPreRender
Details Object reference not set to an instance of an object.

protected override void OnWebPartPreRender()
        {

            //resultsGrid.Enabled = false;
            resultsGrid.DataSource = GetListOfWaitingDocuments();
            //resultsGrid.Enabled = true;
            resultsGrid.DataBind();


        }

        private DataView GetListOfWaitingDocuments()
        {

            //Get the directory specified by the user
            DirectoryInfo dirCustom = new DirectoryInfo(waitingFolder);

            // We'll store the file list here
            FileInfo[] filCustom;

            filCustom = dirCustom.GetFiles("*.xml");

            DataView myDataView = default(DataView);
            DataTable waitingDocuments = new DataTable();
            waitingDocuments.Columns.Add("Name");
            waitingDocuments.Columns.Add("Length");
            waitingDocuments.Columns.Add("LastWriteTime");
            waitingDocuments.Columns.Add("Extension");
            DataRow myDataRow = default(DataRow);


            // Loop through the file list
            foreach (FileInfo theFile in filCustom)
            {
                myDataRow = waitingDocuments.NewRow();

                myDataRow["Name"] = theFile.Name;
                myDataRow["Length"] = theFile.Length;
                myDataRow["LastWriteTime"] = theFile.LastWriteTime;
                myDataRow["Extension"] = theFile.Extension;
                waitingDocuments.Rows.Add(myDataRow); 
            }

            
            myDataView = waitingDocuments.DefaultView;
            return myDataView;
            
        }

        // ASP.NET controls
        Label headingLabel;
        GridView resultsGrid;

Open in new window

0
 
Maheshwar RSoftware DeveloperCommented:
hey u just added the colomn names thats all .. u have to bind the colomn names to the respected fields..  u can do that by in the code.
0
 
hmcgeehanAuthor Commented:
omaheshwar
I did that now I get  ...
Method OnWebPartPreRender
Details Object reference not set to an instance of an object.
0
 
anvCommented:
Can you please check the column names by traversing through the list of columns, just to be sure?
0
 
hmcgeehanAuthor Commented:
I don't understand why I need to check them.

I explicitly declare them ...

waitingDocuments.Columns.Add("Name");
            waitingDocuments.Columns.Add("Length");
            waitingDocuments.Columns.Add("LastWriteTime");
            waitingDocuments.Columns.Add("Extension");


then assign to them in the loop


myDataRow["Name"] = theFile.Name;
                myDataRow["Length"] = theFile.Length;
                myDataRow["LastWriteTime"] = theFile.LastWriteTime;
                myDataRow["Extension"] = theFile.Extension;


surely that part is correct?
thanks
0
 
Maheshwar RSoftware DeveloperCommented:
is xml ur bonding is empty..? or try to see that ur not calling the function before binding....
0
 
ROMA CHAUHANProject LeadCommented:
Here the problem is with line...GridView resultsGrid;
Add the GridView from the UI, just drag and drop the gridView on page and name it as resultsGrid. Comment the GridView resultsGrid; line from code behind. Your code will work fine.

Here you are getting error because you are assigning the datasource to the control which is not initalized. Just try what i have suggested and let me know if u have any problem.
0
 
hmcgeehanAuthor Commented:
roma2208 the problem is I have to declare them this way as it's a web part for Sharepoint 2007
0
 
ROMA CHAUHANProject LeadCommented:
can u declare it as GridView resultsGrid=new GridView (); ????
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now