Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hai,

I am developing the project for reading xml files into dataset.But i got the error.Below i has send my coding for this application.plz clarify it.
//authors.xml//
XML
<authors_table>
  <authors>
    <au_id>172-32-1176</au_id>
    <au_lname>White</au_lname>
    <au_fname>Johnson</au_fname>
    <phone>408 496-7223</phone>
    <address>10932 Bigge Rd.</address>
    <city>Menlo Park</city>
    <state>CA</state>
    <zip>94025</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>213-46-8915</au_id>
    <au_lname>Green</au_lname>
    <au_fname>Margie</au_fname>
    <phone>415 986-7020</phone>
    <address>309 63rd St. #411</address>
    <city>Oakland</city>
    <state>CA</state>
    <zip>94618</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>238-95-7766</au_id>
    <au_lname>Carson</au_lname>
    <au_fname>Cheryl</au_fname>
    <phone>415 548-7723</phone>
    <address>589 Darwin Ln.</address>
    <city>Berkeley</city>
    <state>CA</state>
    <zip>94705</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>267-41-2394</au_id>
    <au_lname>Hunter</au_lname>
    <au_fname>Anne</au_fname>
    <phone>408 286-2428</phone>
    <address>22 Cleveland Av. #14</address>
    <city>San Jose</city>
    <state>CA</state>
    <zip>95128</zip>
    <contract>true</contract>
  </authors>
  <authors>
    <au_id>274-80-9391</au_id>
    <au_lname>Straight</au_lname>
    <au_fname>Dean</au_fname>
    <phone>415 834-2919</phone>
    <address>5420 College Av.</address>
    <city>Oakland</city>
    <state>CA</state>
    <zip>94609</zip>
    <contract>true</contract>
  </authors>
</authors_table>



Then i add 1 datagrid, 1textbox and 2button controls in my form
//code behind//
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication100
{
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet("authors");
            
        }

        private void btnReadXML_Click(object sender, EventArgs e)
        {
            string filePath = "C:/Documents and Settings/sridharan/My Documents/Visual Studio 2008/Projects/WindowsFormsApplication100/authors.xml";
            ds.ReadXml(filePath);
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "authors";
            dataGridView1.CaptionText = dataGridView1.DataMember;
            
        }

        private void BtnShowSchema_Click(object sender, EventArgs e)
        {
            System.IO.StringWriter swXML = new System.IO.StringWriter();
            ds.WriteXmlSchema(swXML);
textBox1.Text = swXML.ToString();
        }
    }
}


In the code behind there is a line

" dataGridView1.CaptionText = dataGridView1.DataMember;"
the error shows like this
///ERROR///
"Error 3 'System.Windows.Forms.DataGridView' does not contain a definition for 'CaptionText' and no extension method 'CaptionText' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\sridharan\My Documents\Visual Studio 2008\Projects\WindowsFormsApplication100\WindowsFormsApplication100\Form1.cs 32 27 ReadingXML"

Then also the error "name ds doesnot exist in current context".Plz clear my doubt.
Posted
Updated 11-Mar-11 1:24am
v2

The error message itself has the answer. DataGridview don't have the property of CaptionText

If you want that property to be there then then create a custom datagrid view extending the datagridview class.
 
Share this answer
 
v2
Comments
ganesh5g 23-Feb-12 0:56am    
how to set the property of Caption text and how to create a custom datagrid view .
The Dataset object ds has been declared in the Form_Load function and hence no other function can use it.
So declare the Database object as a field.
Like this :

C#
public partial class Form1 : Form
   {
       DataSet ds;
       public Form1()
       {
       }


Now this ds will be available to this class's functions.
And in the form_load, just instantiate it.

C#
private void Form1_Load(object sender, EventArgs e)
        {
            ds = new DataSet("authors");
        }


About the CaptionText, that's because your DatagridView does not have the property CaptionText.
 
Share this answer
 
v2
Hi Frnds,

me too getting same error then say how to create a custom datagridview extending the datagridview class and how to set the property of Caption text


dataGridView1.CaptionText= dataGridView1.DataMember;
{
if (dataGridView1.CaptionText =="")
dataGridView1.CaptionText ="authors DataGrid";
}
in the above coding part i am getting error as ('System.Windows.Forms.DataGridView' does not contain a definition for 'CaptionText' and no extension method 'CaptionText' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?)


Please say the proper solution Frnds.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900