Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 18th, 2007, 08:19 PM
Authorized User
Join Date: Jul 2007
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Read from data grid

  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);
  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


  #2 (permalink)  
Old July 20th, 2007, 04:54 AM
Registered User
Join Date: Jul 2007
Location: beijing, beijing, China.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to asdf4525qd

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);
   OleDbCommand Mycom = new OleDbCommand();
   Mycom.Connection = MyCon;
   Mycom.CommandType = CommandType.Text;
   Mycom.CommandText = SQLStr;
   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.

  #3 (permalink)  
Old July 23rd, 2007, 03:12 AM
Authorized User
Join Date: Jul 2007
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts

Belated thanks,


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 07:48 AM.

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