ADO.Net

  • 12 years ago


    I am a Newbie in dot Net..so am really sorry if you feels that my doubt is too kiddish
    ADO.Net is a disconnected database architecture with Dataset as the core object in its object hierarchy.


    For explaining my doubt, I am taking an example of a table named "Employee" in the database named "Company
    Employee table has an autonumberd primary key column "EmployeeID"


    Consider a networked  multiuser environment or Internet itself.


    Suppose Employee table has 10 rows in it. A user named "A" retrieves all of the rows and caches in his client side Dataset.
    He then deleted the 10th row and then started editing some of the columns in the 9th row.
    He then adds 11th row with the primary key "EmployeeID"  (lets say 100 as the next autonumber generated. So the new record he created as 100 as the "EmployeeID")


    These changes hasnt yet been physically updated to the database.



    At this same point of time another user named "B" extracted the employee table rows from the database and cached in his client side Dataset.First he deleted the 9th row and started editing the 10th row's data. then
    adds 11th row . Since the above changes hasnt been yet updated to the database, the new row created by B also has 100 as the  primary key(autonumber)..



    {    Even if the primary key is not auto number, let me say that incidently both of them gave 100 as the primary key value for the new rows they created    }


    Now from this moment..let me say.. first the user B calls the Dataset.Update method and after tht User B calls the Dataset.Update method.


    Can anybody explain me what exactly hapens in database whn both of the statements executed?..


    Is it that all the valuable data which A has edited in 9th row has gone ??..so as B has edited the 10th row???.. wil it be an
    incosistent database?..Then what abt the new row both has added with the same primary key value???



    Can anybody explain me these anamolies please??



    Another doubt is, we can create a sequence in Oracle database.  Can i make it available in a dataset ???

  • 12 years ago

    from my understanding of u r problem what will happen here is


    u have set one columnas primary key in the database
    then u cannot update 2 rows with the same id


    hare if A has called the update first then A's update will be valid
    then B called the Update Method then on saving it would give error


    there is 2 event in sqldataadapter


    SqlDataAdapter1RowUpdated
    SqlDataAdapter1
    RowUpdating


    here u can see the rows getting updating its state everything



    in u r case what u can do is
    put a Catch xyz As System.Data.SqlClient.SqlException
    just below the update satement.


    see this
    Try


               SqlDataAdapter1.Update(ds)
             Catch xyz As System.Data.SqlClient.SqlException
           Catch ex As Exception


           End Try


    and automatically a small error symbol will be shown next to that duplicate row.


    ie xyz will show similar message
       xyz.message    "Violation of PRIMARY KEY constraint 'PK_Employees'. Cannot insert duplicate key in object 'Employees'."    String



    2
    Another doubt is, we can create a sequence in Oracle database.  Can i make it available in a dataset ???


    yes u can set the seed ie theway it should be incremented and atrting value of like


    AutoIncrement()
    AutoIncrementSeed()


Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The question of whether computers can think is just like the question of whether submarines can swim.” - Edsger W. Dijkstra