Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 3rd, 2003, 05:13 AM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default a DataGrid question

an empty dataset binded in a dataGrid
when the dataGrid is in a form ,it has an empty row,
when the dataGrid is in a MDIForm,it has two rows,why?


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication8
{
    /// <summary>
    /// Form1 µÄժҪ˵Ã÷¡£
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem menuItem1;
        private System.Windows.Forms.MenuItem menuItem2;
        /// <summary>
        /// ±ØÐèµÄÉè¼ÆÆ÷±äÁ¿¡£
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Windows ´°ÌåÉè¼ÆÆ÷Ö§³ÖËù±ØÐèµÄ
            //
            InitializeComponent();

            //
            // TODO: ÔÚ InitializeComponent µ÷ÓúóÌí¼ÓÈκι¹Ô캯Êý´úÂ ë
            //
        }

        /// <summary>
        /// ÇåÀíËùÓÐÕýÔÚʹÓõÄ×ÊÔ´¡£
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Éè¼ÆÆ÷Ö§³ÖËùÐèµÄ·½·¨ - ²»ÒªÊ¹ÓôúÂë±à¼­Æ÷ÐÞ¸Ä
        /// ´Ë·½·¨µÄÄÚÈÝ¡£
        /// </summary>
        private void InitializeComponent()
        {
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            //
            // mainMenu1
            //
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem1});
            //
            // menuItem1
            //
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.menuItem2});
            this.menuItem1.Text = "test";
            //
            // menuItem2
            //
            this.menuItem2.Index = 0;
            this.menuItem2.Text = "111";
            this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.IsMdiContainer = true;
            this.Menu = this.mainMenu1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.Form1_Load);

        }
        #endregion

        /// <summary>
        /// Ó¦ÓóÌÐòµÄÖ÷Èë¿Úµã¡£
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {

        }

        private void menuItem2_Click(object sender, System.EventArgs e)
        {
                        //Èç¹ûÓÃÕâ¶Î³ÌÐòDATAGRIDÖÐÖ»ÓÐÒ »¸ö¿ÕÐÐ
            //Form2 myform = new Form2();
            //myform.Show();


                        //ÓÃÕâ¶Î³ÌÐòDATAGRIDÖÐÓÐÁ½¸ö¿ÕÐ Ð
            Form2 newMDIChild = new Form2();
            newMDIChild.MdiParent = this;
            newMDIChild.Show();
        }
    }
}



using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace WindowsApplication8
{
    /// <summary>
    /// Form2 µÄժҪ˵Ã÷¡£
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
        /// <summary>
        /// ±ØÐèµÄÉè¼ÆÆ÷±äÁ¿¡£
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form2()
        {
            //
            // Windows ´°ÌåÉè¼ÆÆ÷Ö§³ÖËù±ØÐèµÄ
            //
            InitializeComponent();

            //
            // TODO: ÔÚ InitializeComponent µ÷ÓúóÌí¼ÓÈκι¹Ô캯Êý´úÂ ë
            //
        }

        /// <summary>
        /// ÇåÀíËùÓÐÕýÔÚʹÓõÄ×ÊÔ´¡£
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Éè¼ÆÆ÷Ö§³ÖËùÐèµÄ·½·¨ - ²»ÒªÊ¹ÓôúÂë±à¼­Æ÷ÐÞ¸Ä
        /// ´Ë·½·¨µÄÄÚÈÝ¡£
        /// </summary>
        private void InitializeComponent()
        {
            //
            // Form2
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Name = "Form2";
            this.Text = "Form2";
            this.Load += new System.EventHandler(this.Form2_Load);

        }
        #endregion

        private void Form2_Load(object sender, System.EventArgs e)
        {
            DataGrid dataGrid = new DataGrid();
            String mySqlStmt =
                "select top 10 CustomerID,CompanyName,ContactName,"+
                "ContactTitle from Customers where CustomerID='1'";
            String myConString =
                "server=localhost;database=Northwind;uid=sa;pwd=;" ;

            System.Data.SqlClient.SqlDataAdapter myDataAdapter =
                new System.Data.SqlClient.SqlDataAdapter(mySqlStmt,myC onString);
            DataSet myDataSet = new DataSet();

            myDataAdapter.Fill(myDataSet,"dataGrid1");
            dataGrid.SetDataBinding(myDataSet,"dataGrid1");


            Controls.Add(dataGrid);
            dataGrid.Height=500;
            dataGrid.Width=700;

        }
    }
}









Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid question hamil VB.NET 2002/2003 Basics 2 July 9th, 2004 05:59 AM
datagrid question... life_s Ng ASP.NET 1.0 and 1.1 Basics 2 October 10th, 2003 11:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.