Creating A Data-Bound Grid In C# With ADO.NET

 
 
Data access is a core of most applications and an ability to efficiently access and modify a database is required for developers on a regular basis. In this article, you will look at accessing SQL-based data utilizing C# and ADO.NET and displaying the data in a data-bound grid control.
 
 
  1. using System.Data;

  2. using System.Data.OleDb;

  3.  

  4. <code>

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

  6. {

  7.  

  8.    string strConn, strSQL;

  9.    strConn = "Provider=Microsoft.JET.OLEDB.4.0;" 

  10.              "data source="   "C:DataAccessNorthwind.mdb";

  11.  

  12.    strSQL = "SELECT CompanyName, ContactName, ContactTitle, " ;

  13.    strSQL = strSQL   "Address, City, Country FROM Customers";

  14.  

  15.    OleDbDataAdapter da = new OleDbDataAdapter(strSQL, strConn);

  16.    DataSet ds = new DataSet();

  17.    da.Fill(ds, "Customers");

  18.  

  19.    dataGrid1.DataMember = "Customers";

  20.    dataGrid1.DataSource=ds;

  21.  

  22. }

  23.  
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 10th Jul 2007
  Rating : No Rating
  Accessed  :  2337
  Submitted by :  ahmedraza
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related C# Source Codes
Database error: Invalid SQL: select FLOOR( AVG(b.rating)) as avg_rating,a.sourcecode_id sourcecode_id ,title,description,author,category_id,skill_level,reference,reference_mail,reference_url,a.user_id user_id,date_entered,source,accessed,dev_id,file_url,total_comments,instruction,registered,authorised,fld_deletemark,fld_code_version,fld_searchkeyword,fld_code_status,category_id from tbl_sourcecode a LEFT JOIN tbl_sourcecodecomment b ON a.sourcecode_id = b.sourcecode_id LEFT JOIN tbl_codecategory c ON a.category_id = c.fld_categoryID where a.fld_deletemark = 'N' AND a.fld_enable_disable= 'Y' AND a.authorised='Y' AND c.fld_groupIDFK='13' AND a.sourcecode_id!='2975' GROUP BY a.sourcecode_id order by a.sourcecode_id DESC limit 0, 5
MySQL Error: 1030 (Got error 122 from storage engine)
Session halted.
Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0