Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 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 July 18th, 2007, 08:19 PM
Authorized User
 
Join Date: Jul 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Read from data grid

Hello,
  I am writing a windows uplication in which i have to read from database ,(while reading i m sorting it using "select * from tabel order by column").display it in datagrid.Edit the datagrid and reflect back the changes(in the sorted order) to database.

 datagrid's readonly property is set to false.
  I am able to read from database and display it.Problem is when i try to save it back .it is not allowing it.


 My code looks like this

  oledbDataAdapter adap;
  DataSet ds = new DataSet();
  oledbCommandBuilder cmd = new oledbCommandBuilder();

   // to fill datagrid
  adap = new oledbDataAdapter(select * from table order by column);
  adap.Fill(ds);
  datagrid1.datasource = ds.Tables[0];

  //to reflect changes to database
 // this is in another function


  cmd.DataAdapter = adap;
  adap.Update(ds); //runtime error is occureing in this statement


  Is there any property required to make datagrid an editable.

  thanking you

watashi






 
Old July 20th, 2007, 04:54 AM
Registered User
 
Join Date: Jul 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to asdf4525qd
Default

Hello Watashi
My code is:
    string Cstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\Managedb.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123456";
   string SQLStr = "Select * From JHK ";
   OleDbConnection MyCon = new OleDbConnection(Cstring);
   MyCon.Open();
   OleDbCommand Mycom = new OleDbCommand();
   Mycom.Connection = MyCon;
   Mycom.CommandType = CommandType.Text;
   Mycom.CommandText = SQLStr;
   Mycom.ExecuteNonQuery();
   dataGridView1.DataSource = MyCon;
   OleDbDataAdapter myadapter = new OleDbDataAdapter();
   DataSet mydataset= new DataSet();
   myadapter.SelectCommand = new OleDbCommand(SQLStr, MyCon);
   myadapter.Fill(mydataset,"JHK"); d
   ataGridView1.DataSource = mydataset.Tables["JHK"];
This is an instance in MSDN. The MSDN is so good that you'll find many code witch you wanted.


 
Old July 23rd, 2007, 03:12 AM
Authorized User
 
Join Date: Jul 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Belated thanks,






Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Grid anything36 Visual Basic 2008 Essentials 0 May 19th, 2008 06:09 AM
How to sort data in a data grid? zaheerabbas.sk ASP.NET 1.0 and 1.1 Basics 3 April 10th, 2007 02:37 PM
Export data from data grid to excel pomoc VB.NET 2002/2003 Basics 0 December 16th, 2005 03:11 PM
Export data from data grid to Excel pomoc Visual Basic 2005 Basics 0 December 16th, 2005 02:56 PM
trying to load db data into data grid itsajourney Beginning VB 6 2 June 7th, 2005 12:05 PM





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