Results 1 to 6 of 6

Thread: Display Data In Data Grid View

  1. #1
    Join Date
    Jan 2009
    Posts
    61

    Display Data In Data Grid View

    Hello, I am learning the C#. net and while learning it, I have got one problem of the displaying the data in the data grid view. If anyone is having information from which I can able to solve this problem then please provide me that. It will be helpful to me. I have tried it, but unable to get the solution. So, if you provide me help then I can do it.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Display Data In Data Grid View

    I have created code below for displaying the Data in the data grid. It will be helpful to you to understand it. But, test it, as I have not compiled it.
    Code:
    SqlConnection connection = new SqlConnection("Data Source =.\\SQLEXPRESS; AttachDbFilename = "+C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Data\\sgbd.mdf "+"; Integrated Security = True; Connect Timeout = 30; User Instance = True");
                try
                {
                    login.Open();
                    string query = ("SELECT * FROM Agent_1");
                    CC adaptation OleDbDataAdapter = new OleDbDataAdapter("query","Connection");
                    OleDbCommandBuilder Cbulder = new OleDbCommandBuilder(CC adaptation);
                    DataTable = JTable new DataTable();
                    CC adaptation.Fill(JTable);
                    DataGridView dgView = new DataGridView();
                    BindingSource bSource = new BindingSource();
                    bSource.DataSource = JTable;
                    dgView.DataSource = BSource;
                    CC adaptation.Update(JTable);
                    dgView.DataSource= JTable;                
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    login.Close();
                }

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Display Data In Data Grid View

    As you know the DataGridView is the control which is used for the showing data from the various outside sources. It also provides you rows and columns for controlling and working on the data. If you make binding of the control with the data source then you can simply create the columns automatically based on your tables of the data source. If also provide you the facility of the hiding, deleting and managing them. It also provide you the facility of the unbounding of the data columns.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Display Data In Data Grid View

    It is having following features:
    • By the help of it you can simply able to mix the bound and unbound data and also virtual columns in your Gridview.
    • It simply provide you the facility of the virtual mode.
    • You will able to get the styles for the different columns, rows or for the complete table.

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: Display Data In Data Grid View

    The code provided by the kelfro requires one change as below:
    Code:
    OleDbDataAdapter = CC adaptation new OleDbDataAdapter(query, connection);
    Instead of ... "query","login");
    Then it will work fine. Else you will get the error as below:
    The format of the initialization string does not conform to specification starting at index 0

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Display Data In Data Grid View

    Display Data In Data Grid View source code:
    Code:
    private void Testing_Load(object  Send, System.EventArgs e)
    {
    OleDbDataAdataadapterpter dataadapter = new OleDbDataAdataadapterpter("SELECT * FROM Emp","Provider=Microsoft.JET.OLEDB.4.0;dataadapterta source=C:\\mcb.mdb" );
    DataSet dataset = new DataSet();
    dataadapter.Fill(dataset, "Emp");
    dataadaptertaGrid1.DataSource = dataset.Tables["Emp"].DefaultView ;
    }
    This is quiet simple code and I don't think it needs any sort of explanation. So, read it carefully and understand it.

Similar Threads

  1. Replies: 2
    Last Post: 23-02-2012, 12:09 PM
  2. Display data in textbox
    By AngelCV in forum Software Development
    Replies: 1
    Last Post: 04-08-2009, 04:32 PM
  3. Replies: 1
    Last Post: 21-07-2009, 09:42 AM
  4. little confused about data grid view
    By Daren in forum Software Development
    Replies: 3
    Last Post: 02-03-2009, 05:21 PM
  5. Replies: 3
    Last Post: 03-02-2009, 10:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,647,866.66896 seconds with 16 queries