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

January 26th, 2004, 11:03 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

January 27th, 2004, 04:53 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

January 27th, 2004, 06:09 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 27th, 2004, 06:18 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

January 27th, 2004, 06:51 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 28th, 2004, 10:51 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
"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.
|
|

January 28th, 2004, 11:27 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your time, nonetheless.
|
|

February 11th, 2004, 11:46 AM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by texasraven
Thanks for your time, nonetheless.
|
Hi,
I think you should call the method acceptchanges of the dataset
Thanks
|
|

August 20th, 2004, 09:17 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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)
|
|

August 20th, 2004, 12:05 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.:)
|
|
 |