.NETGURU
updating dataset
Messages   Related Types
This message was discovered on microsoft.public.dotnet.distributed_apps.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Robin
In a .Net solution that has a DAL, Class and Business logic.
When recreating a dataset from the class the records are inserted into the
database from the dataset instead of updating. This is using the dataset
merge command.

Is there any settings that should be used to ensure that the data is
updating instead of inserted?

Reply to this message...
 
    
Saurabh Nandu (VIP)
Hi,

I am not too sure if this works, but here's what i feel is the problem.

DataAdapter.Update works based on the RowState of the DataRow.

So a DataRowState.Added will lead to the record being inserted into the
database, while a DataRowState.Modified will lead to the record being updated
in the database.

Now the RowState property of the DataRow within a DataTable is read-only.
But the only way to modify it is to first add the row in the DataTable in you
class and then modify its values.

ie
(from MSDN)

private void DemonstrateRowState() {
//Run a function to create a DataTable with one column.
DataTable myTable = MakeTable();
DataRow myRow;

// Create a new DataRow.
myRow = myTable.NewRow();
// Detached row.
Console.WriteLine("New Row " + myRow.RowState);

myTable.Rows.Add(myRow);
// New row.
Console.WriteLine("AddRow " + myRow.RowState);

myRow["FirstName"] = "Scott";
// Modified row.
// After Modification the Row should now Update to the Database
Console.WriteLine("Modified " + myRow.RowState);

}

private DataTable MakeTable(){
// Make a simple table with one column.
DataTable dt = new DataTable("myTable");
DataColumn dcFirstName = new DataColumn("FirstName",
Type.GetType("System.String"));
dt.Columns.Add(dcFirstName);
return dt;
}

Regards,
Saurabh Nandu
[ www.AksTech.com ]
[ www.MasterCSharp.com ]

"Robin" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Console
System.Data.Common.DataAdapter
System.Data.DataColumn
System.Data.DataRow
System.Data.DataRowState
System.Data.DataTable
System.String
System.Type




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification