How to use db transcation for an OleDb token places in a loop?

There comes an interesting problem for you, it seems very easy in code:
using (OleDbConnection con = new OleDbConnection(……))
OleDbCommand cmd = new OleDbCommand(con);
OleDbTranscation trans = con.BeginTranscation();
cmd.CommandText = "update xxx set field1=@field1,field2=@field2 where field3=@field3";
//Suppose "pCollection" is a collection variable defined before, and this is a stack type.
Point p = pCollection.Pop();
while(pCollection.Count!=0)
cmd.Parameters["@field1"].Value = p.Field1;
cmd.Parameters["@field2"].Value = p.Field2;
cmd.Parameters["@field3"].Value = p.Field3;
cmd.Parameters["@field4"].Value = p.Field4;
p = pCollection.Pop();
cmd.ExecuteNonQuery();
trans.Commit();
The codes above seems roughly right, however if you run it and you will find that only the last record is updated, because the parameters of SqlCommand are overridden by the latter time of loop, and all the previous loop's parameters are referring to the same
parameters of SqlCommand, so only the last time the parameters' values take action. And all the transcations are pointing to the last time of updating record.So my question is How
to make each updating statement takes action within the whole transcation (each updating SQL has different values of parameters)?
ASP.NET Forum
Other Discussion Forums
FreeRice Donate
Issues to report
Free Tech Books Search and Download

The below worked for me:
using (OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
con.Open();
System.Data.OleDb.OleDbTransaction trans = con.BeginTransaction();
cmd.Transaction = trans;
cmd.CommandText = "update Category set Category=? where CatId=?";
int i = 2;
cmd.Parameters.Add("@field1", OleDbType.VarChar);
cmd.Parameters.Add("@field2", OleDbType.Integer);
while (i != 0)
cmd.Parameters["@field1"].Value = i.ToString();
cmd.Parameters["@field2"].Value = i;
i--;
cmd.ExecuteNonQuery();
trans.Commit();
Fouad Roumieh

Similar Messages

  • Hi Any body Knows How to use CAT Tool for Up Loading?

    Hi
    If any body knows how to use CAT Tool for up loading transactions, explain the steps.
    Our requirement is, we want to up load transactions like Oppor , Quotation,Order etc...we want to up load these transcations from Local system to CRM Server
    how to do this? Let me know the steps.
    Regards
    Venkat

    If you have 10,000 or less, CATT is a reasonable method, but I would suspect that you have far more than that if you're needing to load transactions.
    LSMW is probably a better way to go if you have more than 10k, but I am not familiar with LSMW

  • How to use Batch operation for two xsodata services?

    Hi All,
    I have two xsodata services. How to use submit batch for two xsodata services
    Thanks,
         Mj

    Gateway Batch Calls from SAPUI5

  • How to use same actions for differ pop-up

    Hi gurus,
    I am using 2 popup in a view.same popup's having same buttons 'Yes', 'No'.when i use 1st one i have to create an action for that Yes button where i put my code for that particular Action.
    But when i used 2nd one the action define for that is not acceptable with differ name.it takes only standard one.
    Now my Query is : How to use same actions for differ pop-up buttons with in a similar view?Where i put my code.
    Plz sugges me.
    <b>Points will be sured.</b>
    Sanket sethi

    Hi,
    Take one integer value attribute in the context of view
    when you r performing action on POP1 set it's value to 1
    when you r performing action on POP2 set it's value to 2
    create one method which receives integer argument, say diaplay(int a)
    In the action call display(wdContext.currentContextElement().get<intvariable>()) by passing the value in the context attribute
    in display() method, Check the value of integer variable..
    if it is 1 then perform action related to POP1
    if it is 2 then perform action related to POP2
    Regards
    LakshmiNarayana

  • How to use same actions for differ pop-up buttons

    Hi gurus,
    I am using 2 popup in a view.same popup's having same buttons 'Yes', 'No'.when i use 1st one i have to create an action for that Yes button where i put my code for that particular Action.
    But when i used 2nd one the action define for that is not acceptable with differ name.it takes only standard one.
    Now my Query is : How to use same actions for differ pop-up buttons with in a similar view?Where i put my code.
    Plz sugges me.
    <b>Points will be sured.</b>
    Sanket sethi

    Hi ,
    u can use the method SUBSCRIBE_TO_BUTTON_EVENT of the IF_WD_WINDOW interface ... to handle the event fired by the popup .....used this method after creating the popup window ...
    regards
    Yash

  • How to Use PM BAPI for equipment Master upload : BAPI_EQUIPMENT_SAVEREPLICA

    Hi ,
      How to use PM BAPI for equipment Master upload : BAPI_EQUIPMENT_SAVEREPLICA.
      May i know what are the input parameters & fields mandatory
      for each Table structures ct_data , ct_datax , it_descript , it_longtext.
      Can any one explain me Step by Step Process.
      B'cos i tried with below code. Equipment is not getting created.
      wa_itab-equipment_ext = '000000000100000001'.
      wa_itab-descript      = 'Test 2 -> Lube Oil Pump'.
      wa_itab-text_language = 'EN'.
      wa_itab-sdescript     = 'Short Description'.
      APPEND wa_itab TO it_itab.
      CLEAR  wa_itab.
      LOOP AT it_itab INTO wa_itab.
        ct_data-ta_guid       = '000000000000000001'.
        ct_data-equipment_ext = wa_itab-equipment_ext.
        ct_data-descript      = wa_itab-descript     .
        ct_data-valid_date    = sy-datum.
        ct_data-equicatgry    = 'M'.
        APPEND ct_data.
        CLEAR  ct_data.
        ct_datax-ta_guid       = '000000000000000001'.
        ct_datax-equipment_ext = 'X'.
        ct_datax-equipment     = 'X'.
        APPEND ct_datax.
        CLEAR  ct_datax.
        it_descript-ta_guid       = '000000000000000001'.
        it_descript-text_language = wa_itab-text_language.
        it_descript-descript      = wa_itab-sdescript    .
        APPEND it_descript.
        CLEAR  it_descript.
        it_longtext-ta_guid        = '000000000000000001'.
        it_longtext-text_language  = wa_itab-text_language.
        it_longtext-text_id        = 'LTXT'.
        it_longtext-text_line      = 'SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS'.
        APPEND it_longtext.
        CLEAR  it_longtext.
        it_longtext-ta_guid        = '000000000000000001'.
        it_longtext-text_language  = wa_itab-text_language.
        it_longtext-text_id        = 'INTV'.
        it_longtext-text_line      = 'aaaaaaaaaaaaaaa'.
        APPEND it_longtext.
        CLEAR  it_longtext.
        it_longtext-ta_guid        = '000000000000000001'.
        it_longtext-text_language  = wa_itab-text_language.
        it_longtext-text_id        = 'INTV'.
        it_longtext-text_line      = 'bbbbbbbbbbbb'.
        APPEND it_longtext.
        CLEAR  it_longtext.
        it_longtext-ta_guid        = '000000000000000001'.
        it_longtext-text_language  = wa_itab-text_language.
        it_longtext-text_id        = 'INTV'.
        it_longtext-text_line      = 'cccccccccccccccc'.
        APPEND it_longtext.
        CLEAR  it_longtext.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
      call BAPI-function in this system
        CALL FUNCTION 'BAPI_EQUIPMENT_SAVEREPLICA'
          TABLES
            ct_data     = ct_data
            ct_datax    = ct_datax
            it_descript = it_descript
            it_longtext = it_longtext
            return      = return
          EXCEPTIONS
            OTHERS      = 1.
        IF sy-subrc = 0.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          WRITE : 'Successful'.
        ENDIF.
        IF NOT return IS INITIAL.
          LOOP AT return.
            IF return-type = 'A' OR return-type = 'E'.
              WRITE : 'Error'.
            ENDIF.
          ENDLOOP.
        ENDIF.
        REFRESH  return.
      ENDLOOP.
    Regards
    SUrendar

    Hi ,
      How to use PM BAPI for equipment Master upload : BAPI_EQUIPMENT_SAVEREPLICA.
      May i know what are the input parameters & fields mandatory
      for each Table structures ct_data , ct_datax , it_descript , it_longtext.
      Can any one explain me Step by Step Process.
      B'cos i tried with below code. Equipment is not getting created.
      wa_itab-equipment_ext = '000000000100000001'.
      wa_itab-descript      = 'Test 2 -> Lube Oil Pump'.
      wa_itab-text_language = 'EN'.
      wa_itab-sdescript     = 'Short Description'.
      APPEND wa_itab TO it_itab.
      CLEAR  wa_itab.
      LOOP AT it_itab INTO wa_itab.
        ct_data-ta_guid       = '000000000000000001'.
        ct_data-equipment_ext = wa_itab-equipment_ext.
        ct_data-descript      = wa_itab-descript     .
        ct_data-valid_date    = sy-datum.
        ct_data-equicatgry    = 'M'.
        APPEND ct_data.
        CLEAR  ct_data.
        ct_datax-ta_guid       = '000000000000000001'.
        ct_datax-equipment_ext = 'X'.
        ct_datax-equipment     = 'X'.
        APPEND ct_datax.
        CLEAR  ct_datax.
        it_descript-ta_guid       = '000000000000000001'.
        it_descript-text_language = wa_itab-text_language.
        it_descript-descript      = wa_itab-sdescript    .
        APPEND it_descript.
        CLEAR  it_descript.
        it_longtext-ta_guid        = '000000000000000001'.
        it_longtext-text_language  = wa_itab-text_language.
        it_longtext-text_id        = 'LTXT'.
        it_longtext-text_line      = 'SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS'.
        APPEND it_longtext.
        CLEAR  it_longtext.
        it_longtext-ta_guid        = '000000000000000001'.
        it_longtext-text_language  = wa_itab-text_language.
        it_longtext-text_id        = 'INTV'.
        it_longtext-text_line      = 'aaaaaaaaaaaaaaa'.
        APPEND it_longtext.
        CLEAR  it_longtext.
        it_longtext-ta_guid        = '000000000000000001'.
        it_longtext-text_language  = wa_itab-text_language.
        it_longtext-text_id        = 'INTV'.
        it_longtext-text_line      = 'bbbbbbbbbbbb'.
        APPEND it_longtext.
        CLEAR  it_longtext.
        it_longtext-ta_guid        = '000000000000000001'.
        it_longtext-text_language  = wa_itab-text_language.
        it_longtext-text_id        = 'INTV'.
        it_longtext-text_line      = 'cccccccccccccccc'.
        APPEND it_longtext.
        CLEAR  it_longtext.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
      call BAPI-function in this system
        CALL FUNCTION 'BAPI_EQUIPMENT_SAVEREPLICA'
          TABLES
            ct_data     = ct_data
            ct_datax    = ct_datax
            it_descript = it_descript
            it_longtext = it_longtext
            return      = return
          EXCEPTIONS
            OTHERS      = 1.
        IF sy-subrc = 0.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          WRITE : 'Successful'.
        ENDIF.
        IF NOT return IS INITIAL.
          LOOP AT return.
            IF return-type = 'A' OR return-type = 'E'.
              WRITE : 'Error'.
            ENDIF.
          ENDLOOP.
        ENDIF.
        REFRESH  return.
      ENDLOOP.
    Regards
    SUrendar

  • How to use Web Serivce for not jsr 172 phone

    Hi:
    Is anyone know, how to use web service for phones that only have standard J2ME package installed (without jsr 172 web service packagenstalled)?
    thank you

    Hi,
    I think you need to write the code for this from scratch (built on top of existing HTTP functionality). There may be open-source J2ME code you could use. I've never tried this so I'm afraid I don't know any more. But maybe that is what you were asking... i.e. does anyone have code that does this already...
    Tx,
    Sam

  • How to use 2 GL for loss made on asset retirement w/o revenue ?

    how to use 2 GL for loss made on asset retirement w/o revenue.
    hello everyone
    i have some trouble.
    my company want to use 2 GL account for asset retirement
    example  some time use GL 6500001  some time use 6500002
    in standard configuration AO90 , field loss made on asset retirement w/o revenue, there is only one field.
    so i can use only one G/L.
    it' s not good if i must to change configuration (and transport request )every time that user need to change GL.
    now i got one idea.
    i know that table T095 keep account determinaton and GL account data.
    so if i make program that change data from table T095 directly. i donot need to change config everytime.
    but i am not sure that this way will make impact other standard program or not.
    i will wait for better idea from everyone.
    please help.

    Substitution consist of several steps  each with two parts:
    1- Prerequisite
    2- Replacement
    If the prerequisite is satisfied (TRUE), substitution (Replacement) is performed.
    Transaction Code: OBBH.
    Thank you
    Javed

  • Explain how to use standard LSMW for MM01

    Can anyone explain how to use standard LSMW for MM01 Tcode.pls explain briefly.

    Hi
    Create a project using 0020 as method.
    Max

  • How to use content conversion for Complex structure

    Hi All,
    I want to know how to use content conversion for the following complex structure:
    Data               
    ...Details            1 to Unbound
    .....Header           1 to 1
    .......HF1
    .......HF2
    .......HF3
    .......ITEM           1 to unbound
    .........ITF1
    .........ITF2
    all are of type string.
    Thanks & Regards,
    Viswanath
    Message was edited by: Viswanath Mente

    Hi,
    In the content conversion,
    give ur
    1.document name as message type
    2.give ur recordstructure as Details,,Header,1,ITEM,
    3.mention ur keyfield.
    conversion parameter
    Header.fieldFixedLength - give the field lengths
    Header.fieldNames=mention all the field name
    Header.keyField=enter the value of keyfield
    Header.endSeparator='nl'
    repeat the same  for Item
    regards
    jithesh

  • How to use java api for function activity in embed oracle workflow?

    because i can't install standalone oracle workflow successfully.
    pls tell me how to use java api for function activity in embed oracle workflow?
    are there some patch or pulg-in package?
    ths a lot...........

    The Java Function Activity Agent is not certified for Oracle Workflow embedded in Oracle Applications. Installing standalone workflow should be a lot easier than what you have found, although it looks like you did hit a Pentium 4 issue with the Oracle Universal Installer. I suggest you contact Oracle Support or Oracle Consulting for assistance.
    because i can't install standalone oracle workflow successfully.
    pls tell me how to use java api for function activity in embed oracle workflow?
    are there some patch or pulg-in package?
    ths a lot...........

  • I want to know that i have recently create an apple id, i want to know that how i can use this id for gsx(without paid) or how to use this id for knowlaged

    i want to know that i have recently create an apple id, i want to know that how i can use this id for gsx(without paid) or how to use this id for knowlaged  
    pls give braef intro about all this things, i have searched on sites but i am not getting exact thing and meaning pls help
    and i wnat to complete hardware exam of mac what should i do
    thanks
    vicckey

    GSX, if you're referring to Apple's service by that name, is available only to employees of Apple-authorized service providers or self-servicing accounts. Unless you are employed by such an organization, you cannot access GSX. If you are employed by such an organization, they should set you up and give you the appropriate login information.
    If you are interested in becoming a certified Apple hardware technician, you can find information here:
    http://training.apple.com/certification/acmt
    Please note, though, that certification does not in and of itself give you access to any of the Apple resouces for support organizations; diagnostic tools, parts ordering, etc. You again must be employed by an authorized Apple support provider before you can gain such access.
    I have no idea what "knowlaged" might be.
    Regards.

  • How to use a dictionary for multi languages when displaying mess

    how to use a dictionary for multi languages when displaying messages??

    1st you have to define new messages in the dictionary:-
    1.     We have to open the application.
    2.     Functional administrator responsibility.
    3.     Core services.
    4.     Messages.
    •     Create message button.
    •     Now fill the name of the message that we want to call it from our code in the Code field.
    •     Fill the application name with short name of the application.
    •     Choose the language.
    •     Set the text you want to be displayed.
    2nd, Now in the CO in the in the process form request you will code throw new OAException ("application short name","Code").
    Now run and see the result.
    3rd we want to use Arabic messages, use the same one you have created for saving as an example but you choose duplicate and set the language Arabic.
    •     Run the page.
    •     Choose preferences.
    •     Current Session language = Arabic.
    Now you can see the result.

  • How to use Bapi BAPI_ACC_DOCUMENT_POST for g/l account document posting

    Hi all,
    I am using BAPI_ACC_DOCUMENT_POST bapi for g/l account documents posting.as I am first time using BAPI in my program.can anyone give details about how to use this BAPI for document postings.what importing parameters need to be passed , which exporting parameters need to be passed and which tables need to be used.  
    Thanks in advance.
    Regards,
    Harshada

    Moderator message - Please search before asking - post locked
    Rob

  • How to use User exit for MM_MATBEL

    Hi
    I want to exclude some material documents while archiving a range of material document through archive Object MM_MATBEL.
    Can you please suggest how to use user exit for this to exclude the material document while archiving.
    Please brief me details.
    Thanks,
    Debadatta

    Hi Debadatta,
    Welcome to SDN.
    Have you looked report program <b>RM07MAAU</b> (Report for Material Document Archiving)?
    Hope this will help.
    Regards,
    Ferry Lianto

Maybe you are looking for

  • CES 2013 and items that will change the way you enjoy your Programming.

    I was able to take time off from work this year, and spend it at the CES 2013 with Verizon in Las Vegas. The things that I was able to see opened my eyes to the future of video entertainment. As a Verizon customer and a Community Leader, I am very pl

  • Where are the many missing features in Numbers found?

    The more that I use Numbers the less likely that I will ever go through the motions of trying to get Numbers to do enough of the things that have to be done in order for my income tax program to work. Like in another post I have some of my smaller ta

  • Error during page load in e-Recruitment

    Hi SAPiians, We are implementing SAP e-Recuitment using BSPs. We are done with the configuration part and also configured the ALE. Also, generated the URLs using RCF_GENERATE_URLS. When i copy and paste the URL in a browser, the logon page pops up. W

  • Finding a number of unused IP addresses based on subnets

    Hello, I am new in PS so I would ask you for understanding in below matter. I need to find a number of unused IP in some subnets in my organization for planning purposes.  I would like to use input file where I could  enter a few subnets, then search

  • An error occurred calling 'LogResult​s' in 'ITSDBLog' of 'DBLog 1.0 Type Library'

    HI, I'm getting this run-time error: Details: An error occurred calling 'LogResults' in 'ITSDBLog' of 'DBLog 1.0 Type Library' An error occurred executing a statement. Schema: ATE_database_multiplePC. Statement: STEP_RESULT. Unknown variable or prope