Multiple Sql Insert String And RollBack With Catch(Exeception)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maheshwag
    New Member
    • Aug 2010
    • 71

    Multiple Sql Insert String And RollBack With Catch(Exeception)

    If I have to insert with two sql table and the place of string is as below:
    Code:
    // Single Record Insert
    String  AA=”Insert into aa(date)values(@date)”;
    
    //Multiple Record Insert with datagridview1
    For(int i=0;i<datagridview1.rows.count-1;i++)
    {
    String BB= “insert into bb(name,amount)values(@name,@amount)”;
    }
    If there are two different strings of sql insert as per as above by single and multiple insert on Button click Event than Is it possible to handle it on single sql command if yes than reply how?.


    But as per I think it is not possible by single SqlCommand and if it is true than there are very big problem to adjust SqlTransaction Class for Rollback and Commit. with try and catch block of the EventHandller


    I am really struggling to insert multiple sql statement as above at one Button1_Click Event. Suggest me proper solution or proper way , technique.
  • Subin Ninan
    New Member
    • Sep 2010
    • 91

    #2
    Create a parameterized stored procedure in sql server which performs above query within transaction block. Execute that stored procedure from your application with parameter values.
    In this case only single SqlCommand object is required and you can take advantages of stored procedures.

    Comment

    Working...