Results 1 to 7 of 7

Thread: 3 operations depending on the first one

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    3 operations depending on the first one

    Hi,

    I need to do 3 inserts into 3 different tables.

    1 Is to link to a TABLE 1 insert values and get the scope identity

    2. Use the scope identity and fill in the rest of the values of TABLE 2.

    3. Make a comparison between a value in TABLE 1 and another in TABLE 3 and Update values into TABLE 3.


    Step 2 and 3 depend on Step1 in a sense that if the insert into Table 1 is not successful then Step 2 and 3 must not exist.

    I have read some info about transaction and rollback. Can experience programmer please tell me how to go about this in the most efficient and secure way.

    Thanks.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: 3 operations depending on the first one

    I'd do this in a stored procedure rather than in code because the three operations you're performing require no 'code' intervention.

    http://www.firstsql.com/tutor5.htm

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: 3 operations depending on the first one

    thanks Menhak,

    Will try but Im not an expert programmer as you are .

    Wish I could post a reputation to you but I need to spread some mysefl before Im allowed for one. Anyways many thanks .

    Might need some more help though to get this going!

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: 3 operations depending on the first one

    hi,

    Any link on how to code the vb.net and the SP please on transaction?

  5. #5
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: 3 operations depending on the first one

    The basic is here...
    Here am executing sp_help stored procedore.
    vb Code:
    1. Try
    2. Imports System.Data.SqlClient
    3.  
    4. Module MainModule
    5.  
    6.     Sub Main()
    7.         Dim connectionString As String = _
    8.           "Connection string"
    9.  
    10.         Dim connection As SqlConnection = New SqlConnection(connectionString)
    11.         connection.Open()
    12.         Try
    13.             Console.WriteLine(Now)
    14.             Dim command As SqlCommand = New SqlCommand("sp_help", connection)
    15.           'Here you want to mention that command Type is stored procedure
    16.            command.CommandType = CommandType.StoredProcedure            
    17.  
    18.             'Execute the command
    19.             Dim adapter As SqlDataAdapter = New SqlDataAdapter(Command)
    20.  
    21.             Dim table As DataTable = New DataTable
    22.             adapter.Fill(table)
    23.             Console.WriteLine(table.Rows.Count)
    24.             Console.Read()
    25.         Finally
    26.             connection.Close()
    27.         End Try
    28.     End Sub
    29.  
    30. End Module
    31. End Try

    hope this will help
    Last edited by vijy; Jun 8th, 2008 at 02:03 AM.
    Visual Studio.net 2010
    If this post is useful, rate it


  6. #6
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: 3 operations depending on the first one

    Visual Studio.net 2010
    If this post is useful, rate it


  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: 3 operations depending on the first one

    You already know how to call stored procedures. If you follow the link I gave on you BEGIN TRANSACTION statements, you only need to start working on your SQL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width