CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2007
    Posts
    122

    problem with dataGridViewand XML

    data not displayed in dataGridView but when i replace dataGridView by dataGrid it work ...why?

    Code:
    SqlConnection sqlCon = new SqlConnection();
                SqlCommand sqlCmd = new SqlCommand();
    
                sqlCon.ConnectionString=@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Administrator\My Documents\ContactsDataBase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                sqlCmd.CommandText = "SELECT CustomerID,CustomerName FROM Customers FOR xml auto";
                sqlCmd.Connection = sqlCon;
                try
                {
                    sqlCon.Open();
                    XmlReader xmlReader = sqlCmd.ExecuteXmlReader();
                    DataSet ds = new DataSet();
                    ds.ReadXml(xmlReader, XmlReadMode.InferSchema);
                    dataGridView1.DataSource = ds;
     
                }
                catch (SqlException)
                {
                    MessageBox.Show("Error Occur");
                }
                finally
                {
                    sqlCon.Close();
                }.

  2. #2
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Re: problem with dataGridViewand XML

    Do you want to Display this in a Gridview(ASP.NET) or Win App?

    if you want to Display this in the ASP.NET or Win App you do the Gridview you need to Supply a Datamember "Name of the Datatable". And if this is a Web App you need to call the DataBind method to Bind the Grid to the Page

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured