Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Display Data In Data Grid View

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 02-02-2010
Member
 
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.

Reply With Quote
  #2  
Old 02-02-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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();
            }
Reply With Quote
  #3  
Old 02-02-2010
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
  #4  
Old 02-02-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #5  
Old 02-02-2010
Member
 
Join Date: May 2008
Posts: 2,383
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:
Quote:
The format of the initialization string does not conform to specification starting at index 0
Reply With Quote
  #6  
Old 02-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Display Data In Data Grid View"
Thread Thread Starter Forum Replies Last Post
How to view pivot table external data source in Microsoft Excel 200 LuniA MS Office Support 2 23-02-2012 12:09 PM
Display data in textbox AngelCV Software Development 1 04-08-2009 04:32 PM
How to view commulated total data use in Reliance net connect broadband+ avinashmunnu India BroadBand 1 21-07-2009 09:42 AM
little confused about data grid view Daren Software Development 3 02-03-2009 05:21 PM
Fetching data from a database and display it in a view - Ruby on Rails Sadashiva Software Development 3 03-02-2009 10:59 PM


All times are GMT +5.5. The time now is 12:29 AM.