2013年9月11日星期三

About OracleDataAdapter update method usage

Why do I use OracleDataAdapter the update method , dataset can be modified in writing back to the database , but you can not write back to insert it ?
Please will advise you, thank you !

beginners .
------ Solution --------------------------------- -----------
paste the code to see the specific issues on which
------ Solution ------------------- -------------------------
OracleDataAdapter you must have defined the InsertCommand property inside the CommandText
------ Solution - -------------------------------------------
dt.AcceptChanges ( ) ;
foreach (DataRow drTemp in dt.Rows)
{
drTemp.SetAdded ();
}
before editing dt above processing
------ For reference only ---------------------------- -----------
are you sure you want to insert the data rowstate is insert?
------ For reference only -------------------------------------- -
code:
ls_sql = "select * from lslszd where mdid =" + ls_mdid;
ls_sql1 = "select * from lslszd_tmp ";

dt = fpc.select (ls_sql). Tables [ 0]; / / fpc.select result of the implementation of ls_sql to dt

OracleDataAdapter oda = new OracleDataAdapter (ls_sql1, ; lszbconn);
oda.Fill (ds_zb);

ds_zb.Tables [0]. Merge (dt); / / dt , there are data

OracleCommandBuilder ocb = new OracleCommandBuilder (oda);

int iii = oda.Update (dt_lszd);
MessageBox.Show (iii.ToString (), " Tip ");
------ For reference only --------------------------------- ------
int iii = oda.Update (dt_lszd);
performed here after the insert update or delete operation that depends on each datarow dt_lszd value of rowstate case
see the LZ description should be ds_zb.Tables [0]. Merge (dt); in
dt elsewhere re- editing, but the data is not inserted .
If you do insert data , try to find out just in time dt call it dt.AcceptChanges (); re- insertion process for subsequent editing .
------ For reference only -------------------------------------- -
RowState is a very important property of DataRow , DataRow represents the current state . RowState are Added, Modified, Unchanged, Deleted, ; Detached several, respectively DataRow being added , modify, change , delete, detachment from the table in some way or make some calls after the operation , these states can be transformed into each other .

DataAdapter can RowState to determine how they affect the database and other storage location if the DataRow state Added, DataAdapter will DataRow added to the database and other storage location , for Modified, Deleted update and delete operations will be performed in fact , the final effect is determined by the operation of the DataAdapter's SelectCommand, UpdateCommand , etc. DbCommand. If , in the UpdateCommand written delete statement or execute a stored procedure that delete operation , then the state will eventually be a DataRow to Modified deleted in the database rather than update .
------ For reference only ---------------------------------- -----
sorry , int iii = oda.Update (dt_lszd);
changed int iii = oda.Update (ds_zb);
------ For reference only ------ ---------------------------------
DataRow 's RowState property how to modify .
------ For reference only ---------------------------------------
LZ considered to understand the meaning . . .
dt and ds_zb is to want the same data as the primary key update process do
do insert different data processing
Really
------ For reference only -------------------------------- -------
9 floor that right, what it means .
------ For reference only ------------------ ---------------------
RowState no problem here , you should check the raw data to see whether there is new content to be inserted .
------ For reference only -------------------------------------- -
ds_zb.Tables [0]. Merge (dt);
I finish this step , I already have my ds_zb to the content.

I just want dt and ds_zb primary keys do update the same data , different data do insert processing .

------ For reference only ---------------------------------- -----
dt in the data is not manually insert LZ , possibly check out from other places ,
datatable want to compare two different , do different treatment , you need to manually set it RowState state can
------ For reference only ------------ ---------------------------
thank you "feng8413142" with your approach , so that the !

------ For reference only ---------------------------------- -----
feng84131421
3x

没有评论:

发表评论