Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 26th, 2004, 11:03 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default Working with IBM AS400

I'm using ADO.NET/OleDB to connect to an AS400 system. I can sucessfully read the data from my AS400 system into a dataset using a data adapter. However, when I try to make changes to the dataset, nothing happens. Here's is some code...

System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(
        "SELECT * from HTUSRLIB/NEWFILE(NEWMEMBER)",dbConn);

      DataSet ds = new DataSet("test");

      da.Fill(ds);

      DataRow dr = ds.Tables[0].NewRow();
      //dr = ds.Tables[0].Rows[0];
      
      for(int i = 0; i < ds.Tables[0].Rows[0].ItemArray.Length; i++)
      {
        dr.ItemArray[i] = ds.Tables[0].Rows[0].ItemArray[i];
      }
      dr.ItemArray[0] = "AA";
      
      
      ds.Tables[0].Rows.Add((DataRow)dr);

Everything gets executed normally, but all the fields in dr still remain DBNull. (So nothing in the for loop, nor
dr.ItemArray[0] = "AA"
works)

Any idea why I cannot change anything in my dataset?

Any help will be greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old January 27th, 2004, 04:53 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I haven't worked with updating data thru datasets since most of what I'm dealing with is web based and essentially "one-shot" SQL calls, but here is an observation.

You instantiate the DataAdapter("da"). That constructor you use, according to the MSDN documentation, "Initializes a new instance of the OleDbDataAdapter class with a SelectCommand." However "da" doesn't have an "UpdateCommand" value, so this is most likely the source of the problem. You need to have an UpdateCommand object set up so the data adapter knows how to update the data.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply With Quote
  #3 (permalink)  
Old January 27th, 2004, 06:09 PM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter, thank you for the reply.

However, I think what you said makes sense in light of updating the datasource, but should you not be able to update your in-memory dataset if you used a select command to build it?

MSDN also says that you should build your select command before calling the fill method of the data adapter, and you should build the update/delete/insert command before calling the update method. My problem is not with the update method (well, I haven't gotten there yet), but with changing the dataset.

Thanks,
Ash

Reply With Quote
  #4 (permalink)  
Old January 27th, 2004, 06:18 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ok, perhaps I misunderstood the original problem.

How are you viewing the data? Perhaps the problem does not lie with the dataset, but rather the method of viewing what's in that dataset.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply With Quote
  #5 (permalink)  
Old January 27th, 2004, 06:51 PM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter, I'm not sure I understand what you mean by viewing the data. However, let me try to elaborate, hoping it answers your question.

I don't have DB2 or any database running on the AS400 system, rather there are a bunch of files. The one I'm reading from has columns and data in each column. This is the first time I'm working with AS400, so I don't know the details, but when using the IBM client access program to download an AS400 file to a text file on PC, I see several columns and data beneath each column.
The data adapter has no problem reading from a file; it reads the column headers and column data just fine.

After I fill my dataset using the data adapter, I can see some fields as being strings and others as decimals. I can see the data in my watch list while I step through the program. When I try to change any field in the dataset, it complains (only in the watch window) that it cannot make that assignment. (I made sure I was trying to assign a string to a string, and a decimal to a decimal).

Would appreciate any help....Thanks

Reply With Quote
  #6 (permalink)  
Old January 28th, 2004, 10:51 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

"Watch list" is what I was looking for. I was wondering how you were actually looking at the contents of the dataset. I thought you might be looking at it with a label in a form, or maybe a datagrid. The case of a datagrid, I would have said that you might need to re-bind the datasource after you make changes, but seeing as you are looking into the dataset with the debugger watch window, you should see the updates. Isn't there some read/write property of a DataSet/DataAdapter? Again, like I mentioned, I don't use datasets for read/write operations, only read so I haven't worked with it from the update side. This is probably beyond my scope of knowledge.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply With Quote
  #7 (permalink)  
Old January 28th, 2004, 11:27 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your time, nonetheless.



Reply With Quote
  #8 (permalink)  
Old February 11th, 2004, 11:46 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by texasraven
 Thanks for your time, nonetheless.



Hi,
I think you should call the method acceptchanges of the dataset

Thanks

Reply With Quote
  #9 (permalink)  
Old August 20th, 2004, 10:17 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The reason your updates don't take is because you have only changed the dataset (in memory) not the actual AS400 table.

Application of updates occurs thru the adapter not the dataset.


In your example you need to issue the update method of the adapter.

da.update(ds)

Reply With Quote
  #10 (permalink)  
Old August 20th, 2004, 01:05 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
da.update(ds)
its not sufficent alone u should be sure u sends UpdateCommand in ur adapter with a valid UpdateCommand or u can use simpily CommandBuilder objects(like SqlCommandBuilder)it sends the essential queries automatically.
Have a Look at this :
http://p2p.wrox.com/topic.asp?TOPIC_...commandbuilder

--------------------------------------------
Mehdi.:)
Reply With Quote
Reply


Thread Tools
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
IBM AS400 Message Errors to show them in .NET appl julenis SQL Server 2000 2 July 12th, 2006 02:45 PM
IBM AS400 Message Errors to show them in .NET appl julenis C# 0 July 12th, 2006 11:28 AM
Data Adaptor - IBM AS400 JesseH ADO.NET 1 February 21st, 2006 01:19 AM
IBM AS400 + VB - retrieving AS400 file definitions gattsi Pro VB Databases 1 July 23rd, 2004 01:55 PM
Jsp out.flush() not working on IBM Websphere AS400 mmalik_altaf Pro JSP 0 June 28th, 2004 10:40 AM



All times are GMT -4. The time now is 10:18 AM.


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