Update Data Set question

Topics: Data Access Application Block
Jul 7, 2009 at 1:38 PM
Edited Jul 7, 2009 at 1:39 PM

I am attempting to update a single table using the UpdateDataSet() method of enterprise library.  The update works, but the results are not what I want.  Instead of the value saved being what I have changed it to in code, it saves the exact string value of Name that is being passed when I add the in parameter.  Can anyone tell me what I am doing wrong?  Below is my code.

	Shared Sub UpdateDatabaseFromDataSet(ByVal ds As DataSet, ByVal con As String)
		 'Handles database connection.
			Dim db As Database

			'Connect to the specified database
			db = DatabaseFactory.CreateDatabase(con)

			Dim query As String = "UPDATE People  SET Name = @Name"
			Using cmd As DbCommand = db.GetSqlStringCommand(query)
				db.AddInParameter(cmd, "@Name", DbType.String, "Name", DataRowVersion.Current)
				db.UpdateDataSet(ds, "People", Nothing, cmd, Nothing, UpdateBehavior.Standard)
			End Using
	End Sub

 

Jul 8, 2009 at 4:55 AM

Hi,

If I understand your question correctly, the value that is being updated in the database is the string "Name" instead of having a specific string value that you defined. I tried your code and try to repro the error that you are encountering but it seems that it doesn't repro the problem. Do you have other pre processing code (for the dataset) before calling the UpdateDatabaseFromDataSet method and passing the dataset? can you post that code?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 8, 2009 at 12:48 PM

Here is how I get the dataset.  The query is just a basic select.  One thing to mention is that this is MS Access.

			
			Shared Function GetDataSet(ByVal query As String, _
			ByVal con As String) As DataSet

			'Handles database connection.
			Dim db As Database

			'Connect to the specified database
			db = DatabaseFactory.CreateDatabase(con)

			'Holds records retrieved from 
			' the database
			Dim ds As New DataSet

			Using cmd As DbCommand = db.GetSqlStringCommand(query)
				ds = db.ExecuteDataSet(cmd)
			End Using

			'Return filled data table
			Return ds
		End Function
After getting the dataset, I bind a flexgrid to the first table in the dataset.  I then make changes to the grid and expect the changes to be persisted to the database when Update is called.  
Jul 8, 2009 at 5:36 PM
Edited Jul 8, 2009 at 5:36 PM

Where did you exactly specify the value of the parameter?  Your db.AddInParameter statement only passed in the command, name of the parameter, data type, source column and the datarowversion.  What version are you using?  Using your exact same code, I was able to save the changes made in the dataset.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 8, 2009 at 5:43 PM

If I am understanding your question correctly, I thought the value was coming from the dataset.  Whatever rows have been updated would be changed using whatever the current value is in the table that I specify in the Update call.  I am using version 3.1.0.0 as enterprise library and Access 2003.  Is it possible for you to post your code?  Maybe it would be easier for me to see exactly what I am doing wrong.

Jul 8, 2009 at 5:49 PM

It is the same code.  Let's make this simpler.  Say you updated your dataset and set a row's Name column to "geemuny", and then you executed the code you posted above, what value is being saved in your database and what value do you expect?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 8, 2009 at 6:22 PM

I would expect "geemuny" to be saved in that particular row in the database.

Jul 8, 2009 at 6:33 PM

Try placing a breakpoint in your UpdateDatabaseFromDataSet method and examine first the content of your dataset.  Just to verify that the dataset passed indeed contains your changes.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 14, 2009 at 7:42 PM

I figured out my problem.  I forgot that in my query I was changing the name of the columns.  Once I updated the parameters to look for the correct column names in the datatable, everything worked fine.  Thank you for your help.