PC Review


Reply
Thread Tools Rate Thread

Adapter Update help!!!!!!!!!

 
 
sujatha
Guest
Posts: n/a
 
      17th Jul 2003
I am fetching data into a dataset from one data source and trying to
update it to another data source using adapter.update method but this
doesnt work. Doesnt give me an error either!!

my code

MiningDataSet = new DataSet();
DataSet TempDataSet = new DataSet();
DataTable ClusterTable = MiningDataSet.Tables.Add ("Cluster");
ClusterTable.Columns.Add ("NODE_UNIQUE_NAME");
ClusterTable.Columns.Add ("NODE_CAPTION" );
DataColumn NodeDist = ClusterTable.Columns.Add
("NODE_DISTRIBUTION",System.Type.GetType("System.Int32") );
NodeDist.AutoIncrement = true;

DataTable ClusterDistTable =
MiningDataSet.Tables.Add("ClusterDist");
ClusterDistTable.Columns.Add("ATTRIBUTE_NAME");
ClusterDistTable.Columns.Add("ATTRIBUTE_VALUE");
ClusterDistTable.Columns.Add("SUPPORT");
ClusterDistTable.Columns.Add("PROBABILITY");
ClusterDistTable.Columns.Add("VARIANCE");
ClusterDistTable.Columns.Add("VALUETYPE");
DataColumn NodeDistChild =
ClusterDistTable.Columns.Add("NODE_DISTRIBUTION" );
NodeDistChild.DataType = System.Type.GetType("System.Int32");


MiningDataSet.Relations.Add
("NodeDistribution",NodeDist,ClusterDistTable.Columns["NODE_DISTRIBUTION"]);

SelectCommand.CommandType = CommandType.Text ;
SelectCommand.CommandText = "SELECT
NODE_UNIQUE_NAME,NODE_CAPTION,NODE_DISTRIBUTION FROM
[mystores].content";

Adapter.TableMappings.Add ("Table","Cluster");
Adapter.TableMappings.Add
("TableNODE_DISTRIBUTION","ClusterDist");

Adapter.Fill(MiningDataSet);

InsertCommand.CommandType = CommandType.Text ;
InsertCommand.CommandText = "INSERT INTO
Cluster(NODE_UNIQUE_NAME,NODE_CAPTION,NODE_DISTRIBUTION) VALUES
(?,?,?)";
InsertCommand.Parameters.Add
("NODE_UNIQUE_NAME",OleDbType.VarChar,50,ClusterTable.Columns["NODE_UNIQUE_NAME"].ToString()
);
InsertCommand.Parameters.Add
("NODE_CAPTION",OleDbType.VarChar,50,ClusterTable.Columns["NODE_CAPTION"].ToString());
InsertCommand.Parameters.Add
("NODE_DISTRIBUTION",OleDbType.VarChar
,50,ClusterTable.Columns["NODE_DISTRIBUTION"].ToString());
CloseDBConnection();
Conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security
Info=False;User ID=sa;pwd=sa12;initial Catalog=IXAppDB;Data
Source=nexdell-05";
OpenDBConnection();
InsertCommand.Connection = Conn;

TempDataSet = MiningDataSet.Clone();
//InsertCommand.CommandText ="select * from organization";
//InsertCommand.ExecuteNonQuery ();
Adapter.Update(TempDataSet,"ClusterDist");
 
Reply With Quote
 
 
 
 
David Sceppa
Guest
Posts: n/a
 
      17th Jul 2003

It looks like you're trying to use the DataAdapter and
DataTable to synchronize your databases. ADO.NET doesn't
inherently support this functionality. However, with a little
understand of how DataAdapter.Update works, you should be able to
handle the scenario you described.

When you call DataAdapter.Update, it looks checks each row's
RowState and executes the corresponding update command
(InsertCommand/UpdateCommand/DeleteCommand) to submit that row's
pending change. The DataAdapter doesn't understand that the
SelectCommand and InsertCommand pointed at different databases,
or know that you wanted to submit all rows as inserts against the
InsertCommand's Connection. It simply sees that all of the rows
have a RowState of Unchanged and assumes there are no changes to
submit.

If prior to calling DataAdapter.Fill, you set
DataAdapter.AcceptChangesDuringFill to False, the rows you create
by calling DataAdapter.Fill will have a RowState of Added. The
subsequent call to DataAdapter.Update will force the DataAdapter
to execute the InsertCommand for each row.

Things get more complex if the "target" database already
contains rows that you retrieved from the "source" database. If
that's a scenario you need to handle, and you simply want to
overwrite such rows in the "target" database, you could set your
InsertCommand to a query like the following:

IF NOT EXISTS(SELECT ID FROM MyTable WHERE ID = @ID)
BEGIN
-- Insert Scenario
INSERT INTO MyTable (...) VALUES (...)
END
ELSE
BEGIN
-- Update Scenario
UPDATE MyTable SET ... WHERE ...
END

Of course, placing this logic in a stored procedure and
calling the stored procedure from the InsertCommand would be an
even better idea.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.

 
Reply With Quote
 
sujatha
Guest
Posts: n/a
 
      18th Jul 2003
yes!!!!!!11
it worked like a charm.
thanks a zillion

(E-Mail Removed) (David Sceppa) wrote in message news:<(E-Mail Removed)>...
> It looks like you're trying to use the DataAdapter and
> DataTable to synchronize your databases. ADO.NET doesn't
> inherently support this functionality. However, with a little
> understand of how DataAdapter.Update works, you should be able to
> handle the scenario you described.
>
> When you call DataAdapter.Update, it looks checks each row's
> RowState and executes the corresponding update command
> (InsertCommand/UpdateCommand/DeleteCommand) to submit that row's
> pending change. The DataAdapter doesn't understand that the
> SelectCommand and InsertCommand pointed at different databases,
> or know that you wanted to submit all rows as inserts against the
> InsertCommand's Connection. It simply sees that all of the rows
> have a RowState of Unchanged and assumes there are no changes to
> submit.
>
> If prior to calling DataAdapter.Fill, you set
> DataAdapter.AcceptChangesDuringFill to False, the rows you create
> by calling DataAdapter.Fill will have a RowState of Added. The
> subsequent call to DataAdapter.Update will force the DataAdapter
> to execute the InsertCommand for each row.
>
> Things get more complex if the "target" database already
> contains rows that you retrieved from the "source" database. If
> that's a scenario you need to handle, and you simply want to
> overwrite such rows in the "target" database, you could set your
> InsertCommand to a query like the following:
>
> IF NOT EXISTS(SELECT ID FROM MyTable WHERE ID = @ID)
> BEGIN
> -- Insert Scenario
> INSERT INTO MyTable (...) VALUES (...)
> END
> ELSE
> BEGIN
> -- Update Scenario
> UPDATE MyTable SET ... WHERE ...
> END
>
> Of course, placing this logic in a stored procedure and
> calling the stored procedure from the InsertCommand would be an
> even better idea.
>
> I hope this information proves helpful.
>
> David Sceppa
> Microsoft
> This posting is provided "AS IS" with no warranties,
> and confers no rights. You assume all risk for your use.
> © 2003 Microsoft Corporation. All rights reserved.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
he Catalyst Control Center is not supported by the driver version of your enabled graphics adapter. Please update your ATI graphics driver, or enable your ATI adapter using the Displays Manager. Keith Windows Vista General Discussion 23 5th Aug 2009 08:59 PM
Data adapter.Update with fields that are part of the update condit =?Utf-8?B?Um9nZXIgVHJhbmNoZXo=?= Microsoft ADO .NET 3 27th Feb 2007 11:31 PM
Adapter.Update() =?Utf-8?B?Sm9obg==?= Microsoft VB .NET 1 18th Sep 2005 08:19 PM
SQL Data Adapter Will not update from ASP.net -- VB Steve Wolfie Microsoft ADO .NET 5 7th May 2005 12:32 AM
Table name req'd for adapter.update ? mklapp Microsoft ADO .NET 3 22nd Dec 2003 09:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:17 PM.