Results 1 to 7 of 7

Thread: Database Note Updated !

  1. #1

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71

    Question Database Note Updated !

    I posted this message in API by misstake.....

    Hi All,

    Finaly I found a way to get my data & I hope it's correct..
    1. Created the DataAdapter
    2. Created the DataSet
    3. Filled the DataAdapter with the my table information.

    Now I need to assign my info which in the table to appear in my form textbox, so to do that I did the following:

    I created a DataRow object:

    For Each myDR In myDS.Tables("Bank").Rows
    Next

    Then assign my form textbox to the fiels:
    Me.txtBankName_e.Text = Trim(myDR("bankname_e"))

    But stuck in 2 things:
    1. Could not assign the myDS to my combo box ( Me.cbSelect.DataSource = myDS)

    2. Could not update the dataset with the modified data :
    myDR.BeginEdit()
    myDR("bankname_e") = Me.txtBankName_e.Text
    myDR.EndEdit()
    myDR.AcceptChanges()
    myDA.Update(myDS, "bank")


    Any suggestions please.

    ADSC
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    this will solve your second question
    OK. umm
    what a nightmare is that .look what I've figured out :

    VB Code:
    1. '//declare the following in the general declaration of the form//
    2.  
    3.  
    4. ' The DataSet.
    5.     Private MYDATASET As New DataSet(" DATA_SET_NAME")
    6.  
    7.     ' Data adapter for the AN_BANK_1 table.
    8.     Dim MYDA1 As New SqlDataAdapter( _
    9.         "SELECT * FROM AN_BANK_1", MYCONN.OCONNECTION)
    10.        
    11.     ' Data adapter for the AN_BANK_2 table.
    12.     Dim MYDA2 As New SqlDataAdapter( _
    13.         "SELECT * FROM AN_BANK_2", MYCONN.OCONNECTION)
    14.  
    15.  
    16. '// then use this call this SUB
    17.  
    18. Private Sub UPDATE_Changes()
    19.         'this sub will update modified and inserted records.
    20.         Dim MODIFIED_DATA As DataSet = MYDATASET.GetChanges( _
    21.                         DataRowState.Modified Or DataRowState.Added)
    22.         If Not (MODIFIED_DATA Is Nothing) Then
    23.             'for modified records
    24.             MYDA1.Update(MODIFIED_DATA)
    25.             'for inserted records
    26.             MYDA2.Update(MODIFIED_DATA, "TestScores")
    27.         End If
    28.  
    29. ' this sub should works with modified and inserted records

    I haven't tried this but seems to work
    Pirate

  3. #3

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71

    Thumbs up

    Oh grate it seems you changed your mind,

    Still it’s not working, but I think I found another way around….

    ‘ Declaration part:
    Dim myDS As New DataSet()
    Dim myDR As DataRow

    Dim mySql = "SELECT * FROM AN_Bank"
    Dim myDA As New SqlDataAdapter(mySql, myConn.oConnection)
    Dim myCB As New SqlCommandBuilder(myDA)

    myDA.UpdateCommand = myCB.GetUpdateCommand

    myDA.Fill(myDS, "Bank")

    ' Fill the DataRow
    myDR = myDS.Tables("Bank").Rows(0)


    ‘ Update part:
    myDR("bankname_e") = "English Bank Name"

    If myDA.Update(myDS, "Bank") = 1 Then
    myDS.AcceptChanges()
    Else
    myDS.RejectChanges()
    End If

    Thanks for your help
    ADSC
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    then nice job . ok what about using GetChanges and Update methods , Can they do the job ???

  5. #5

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    Ummm, I need to try it and I'll let you know .....

    * * * Please Wait * * *

    **** Cocking The Code ****
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    hehe

  7. #7

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    First error you need to add the table name :
    MYDA1.Update(MODIFIED_DATA, "TabelName")

    The second error I got :
    (Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.)
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

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