Results 1 to 16 of 16

Thread: DataSet updated but not updating the database???? Help!!!

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    DataSet updated but not updating the database???? Help!!!

    when i run the following code the State column in the dataset gets updated, but i can't get it to update with the database. thanx in advance for any help...it's monday what can i say


    VB Code:
    1. Private Sub SaveNewShipLog()
    2.         Dim LibInfoAdp As OleDbDataAdapter 'For Library Information Table access
    3.         Dim LibProjAdp As OleDbDataAdapter 'For Project Table access
    4.         Dim ShipLogAdp As OleDbDataAdapter 'For Ship Log Table access
    5.         Dim ShipLstAdp As OleDbDataAdapter 'For Ship Log List Table access
    6.         Dim adoBldr As OleDbCommandBuilder
    7.         Dim adoDs As DataSet
    8.  
    9.         Try
    10.             'Setup the adapters
    11.             LibInfoAdp = New OleDbDataAdapter(Me.BulidShippingLogSQL("library information"), adoCnn)
    12.             LibProjAdp = New OleDbDataAdapter(Me.BulidShippingLogSQL("lib_proj_tbl"), adoCnn)
    13.             ShipLogAdp = New OleDbDataAdapter(Me.BulidShippingLogSQL("ship_log_tbl"), adoCnn)
    14.             ShipLstAdp = New OleDbDataAdapter(Me.BulidShippingLogSQL("shp_log_lstn_tbl"), adoCnn)
    15.  
    16.             'Make sure the adapters that the primary key.
    17.             LibInfoAdp.MissingSchemaAction = MissingSchemaAction.AddWithKey
    18.             LibProjAdp.MissingSchemaAction = MissingSchemaAction.AddWithKey
    19.             ShipLogAdp.MissingSchemaAction = MissingSchemaAction.AddWithKey
    20.             ShipLstAdp.MissingSchemaAction = MissingSchemaAction.AddWithKey
    21.  
    22.             'Fill the dataset.
    23.             adoDs = New DataSet
    24.             LibInfoAdp.Fill(adoDs, "[Library Information]")
    25.             LibProjAdp.Fill(adoDs, "lib_proj_tbl")
    26.             ShipLogAdp.Fill(adoDs, "ship_log_tbl")
    27.             ShipLstAdp.Fill(adoDs, "shp_log_lstn_tbl")
    28.  
    29.             'Test for library information change
    30.             Me.LibraryInfoUpdateTest(LibInfoAdp, adoDs)
    31.  
    32.             'Dim dRow As DataRow = adoDs.Tables("ship_log_tbl").NewRow()
    33.             'dRow("PROJ_ID") = lngPROJ_ID
    34.             'dRow("LIB_TYPE_ID") = 1
    35.             'dRow("SHP_MTH_ID") = 1
    36.             'dRow("NSO_ID") = 1
    37.             'dRow("ship_date") = Today
    38.             'dRow("attetion_of") = "tester"
    39.             'dRow("cd_cs_person") = "tester2"
    40.             'dRow("lst_pricing") = True
    41.  
    42.             'adoDs.Tables("ship_log_tbl").Rows.Add(dRow)
    43.  
    44.             'adoBldr = New OleDbCommandBuilder(ShipLogAdp)
    45.             'ShipLogAdp.Update(adoDs, "ship_log_tbl")
    46.             'adoBldr.Dispose()
    47.             'adoBldr = Nothing
    48.  
    49.         Catch ex As Exception
    50.             MsgBox(ex.Message)
    51.         End Try
    52.     End Sub
    53.  
    54.     Private Function LibraryInfoUpdateTest(ByRef adp As OleDbDataAdapter, ByVal ds As DataSet) As Boolean
    55.         Dim dRow As DataRow = ds.Tables("[Library Information]").Rows(0)
    56.         Dim bld As New OleDbCommandBuilder(adp)
    57.  
    58.         Debug.Write(dRow("State"))
    59.         dRow("State") = "PA"
    60.         Debug.Write(dRow("State"))
    61.         dRow.AcceptChanges()
    62.         adp.Update(ds, "[Library Information]")
    63.         bld.Dispose()
    64.         bld = Nothing
    65.     End Function
    66.  
    67.     Private Function BulidShippingLogSQL(ByVal DB_Table_Name As String) As String
    68.         Select Case DB_Table_Name.ToLower
    69.             Case "library information"
    70.                 Return "SELECT " & _
    71.                             "[Library Information].ID, " & _
    72.                             "[Library Information].[Library Name], " & _
    73.                             "[Library Information].Address1, " & _
    74.                             "[Library Information].Address2, " & _
    75.                             "[Library Information].City, " & _
    76.                             "[Library Information].State, " & _
    77.                             "[Library Information].Zip, " & _
    78.                             "[Library Information].[Library Type] " & _
    79.                        "FROM " & _
    80.                             "[Library Information] " & _
    81.                        "WHERE " & _
    82.                             "[Library Information].ID = " & lngLIB_ID
    83.             Case "lib_proj_tbl"
    84.                 Return "SELECT * " & _
    85.                        "FROM " & _
    86.                             "lib_proj_tbl " & _
    87.                        "WHERE " & _
    88.                             "PROJ_ID = " & lngPROJ_ID & " AND LIB_ID = " & lngLIB_ID
    89.             Case "ship_log_tbl"
    90.                 Return "SELECT * FROM ship_log_tbl"
    91.             Case "shp_log_lstn_tbl"
    92.                 Return "SELECT * FROM shp_log_lstn_tbl"
    93.             Case Else
    94.  
    95.         End Select
    96.     End Function

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Get rid of the AcceptChanges line. That resets the RowState property of all rows to Unchanged. Try that and see if it helps.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310
    i tried that and it get the following error:

    Syntax error (missing operator) in query expression '( (ID = ?) AND ((? = 1 AND Library Name IS NULL) OR (Library Name = ?)) AND ((? = 1 AND Address1 IS NULL) OR (Address1 = ?)) AND ((? = 1 AND Address2 IS NULL) OR (Address2 = ?)) AND ((? = 1 AND City IS NULL) OR (City = ?)) AND ((? = 1 AND State IS NULL) O'.

    also when i look at the state of the bld object for OleCommandBuilder for the UpdateCommand it is set to Nothing. I thought that the commandbuilder is suppose to know what to select based on what operation you are doing?


    thanx for suggestion

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  4. #4

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310
    *bump*

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  5. #5

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310
    Can anybody give me a suggestion? I have even tried an example that I found in a book...and it doesn't even work...so I'm really confused...


    Thanx in advance.

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  6. #6

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310
    Ok as you can see from the code, I have most of commented out. the only code that isn't commented is the where i build the SQL and the code that should update the database...i say should be with the exception of table names and the names of variables and the function that builds and returns the SQL....it's the same structure and same code from a book....and it still doesn't work....what gives??? *** BIG TIME ***!!!!!!!!!!!! Here's the code.


    VB Code:
    1. Private Sub SaveNewShipLog()
    2.         Dim LibInfoAdp As OleDbDataAdapter 'For Library Information Table access
    3.         'Dim LibProjAdp As OleDbDataAdapter 'For Project Table access
    4.         'Dim ShipLogAdp As OleDbDataAdapter 'For Ship Log Table access
    5.         'Dim ShipLstAdp As OleDbDataAdapter 'For Ship Log List Table access
    6.         Dim adoBldr As OleDbCommandBuilder
    7.         Dim adoDs As DataSet
    8.  
    9.         Try
    10.             'Setup the adapters
    11.             LibInfoAdp = New OleDbDataAdapter(Me.BulidShippingLogSQL("library information"), adoCnn)
    12.             'LibProjAdp = New OleDbDataAdapter(Me.BulidShippingLogSQL("lib_proj_tbl"), adoCnn)
    13.             'ShipLogAdp = New OleDbDataAdapter(Me.BulidShippingLogSQL("ship_log_tbl"), adoCnn)
    14.             'ShipLstAdp = New OleDbDataAdapter(Me.BulidShippingLogSQL("shp_log_lstn_tbl"), adoCnn)
    15.  
    16.             'Make sure the adapters that the primary key.
    17.             'LibInfoAdp.MissingSchemaAction = MissingSchemaAction.AddWithKey
    18.             'LibProjAdp.MissingSchemaAction = MissingSchemaAction.AddWithKey
    19.             'ShipLogAdp.MissingSchemaAction = MissingSchemaAction.AddWithKey
    20.             'ShipLstAdp.MissingSchemaAction = MissingSchemaAction.AddWithKey
    21.  
    22.             adoBldr = New OleDbCommandBuilder(LibInfoAdp)
    23.             'Fill the dataset.
    24.             adoDs = New DataSet
    25.             LibInfoAdp.Fill(adoDs, "[Library Information]")
    26.             'LibProjAdp.Fill(adoDs, "lib_proj_tbl")
    27.             'ShipLogAdp.Fill(adoDs, "ship_log_tbl")
    28.             'ShipLstAdp.Fill(adoDs, "shp_log_lstn_tbl")
    29.  
    30.             'Test for library information change
    31.             'Me.LibraryInfoUpdateTest(LibInfoAdp, adoDs)
    32.  
    33.             adoDs.Tables("[Library Information]").Rows(0)("State") = "PA"
    34.  
    35.             LibInfoAdp.Update(adoDs, "[Library Information]")
    36.             adoBldr.Dispose()
    37.             adoBldr = Nothing
    38.             'Dim dRow As DataRow = adoDs.Tables("ship_log_tbl").NewRow()
    39.             'dRow("PROJ_ID") = lngPROJ_ID
    40.             'dRow("LIB_TYPE_ID") = 1
    41.             'dRow("SHP_MTH_ID") = 1
    42.             'dRow("NSO_ID") = 1
    43.             'dRow("ship_date") = Today
    44.             'dRow("attetion_of") = "tester"
    45.             'dRow("cd_cs_person") = "tester2"
    46.             'dRow("lst_pricing") = True
    47.  
    48.             'adoDs.Tables("ship_log_tbl").Rows.Add(dRow)
    49.  
    50.             'adoBldr = New OleDbCommandBuilder(ShipLogAdp)
    51.             'ShipLogAdp.Update(adoDs, "ship_log_tbl")
    52.             'adoBldr.Dispose()
    53.             'adoBldr = Nothing
    54.  
    55.         Catch ex As Exception
    56.             MsgBox(ex.Message)
    57.         End Try
    58.     End Sub
    59.  
    60.     'Private Function LibraryInfoUpdateTest(ByVal adp As OleDbDataAdapter, ByVal ds As DataSet) As Boolean
    61.         'Dim bld As New OleDbCommandBuilder(adp)
    62.         'Dim dRow As DataRow = ds.Tables("[Library Information]").Rows(0)
    63.  
    64.         'adp.UpdateCommand = bld.GetUpdateCommand()
    65.  
    66.         'ds.Tables("[Library Information]").Rows(0)("State") = "PA"
    67.         'adp.Update(ds, "[Library Information]")
    68.         'bld.Dispose()
    69.         'bld = Nothing
    70.     'End Function
    71.  
    72.     Private Function BulidShippingLogSQL(ByVal DB_Table_Name As String) As String
    73.         Select Case DB_Table_Name.ToLower
    74.             Case "library information"
    75.                 Return "SELECT " & _
    76.                             "ID, " & _
    77.                             "[Library Name], " & _
    78.                             "Address1, " & _
    79.                             "Address2, " & _
    80.                             "City, " & _
    81.                             "State, " & _
    82.                             "Zip, " & _
    83.                             "[Library Type] " & _
    84.                        "FROM " & _
    85.                             "[Library Information] " & _
    86.                        "WHERE " & _
    87.                             "ID = " & lngLIB_ID
    88.             Case "lib_proj_tbl"
    89.                 Return "SELECT * " & _
    90.                        "FROM " & _
    91.                             "lib_proj_tbl " & _
    92.                        "WHERE " & _
    93.                             "PROJ_ID = " & lngPROJ_ID & " AND LIB_ID = " & lngLIB_ID
    94.             Case "ship_log_tbl"
    95.                 Return "SELECT * FROM ship_log_tbl"
    96.             Case "shp_log_lstn_tbl"
    97.                 Return "SELECT * FROM shp_log_lstn_tbl"
    98.             Case Else
    99.  
    100.         End Select
    101.     End Function

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  7. #7
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Hmmm....I usually just write my own SQL and not use the CommandBuilders, but I would suggest that you try creating your command builder after you have filled the dataadapter, not before hand.



    'Fill the dataset.
    adoDs = New DataSet
    LibInfoAdp.Fill(adoDs, "[Library Information]")

    adoBldr = New OleDbCommandBuilder(LibInfoAdp)

    That is just a thought though....
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I believe the AcceptChanges should come after Update.

    For example:

    VB Code:
    1. Private Sub DataUpdate()
    2.         Dim da As SqlClient.SqlDataAdapter
    3.         Dim cbuild As SqlClient.SqlCommandBuilder
    4.         Dim dr As DataRow
    5.         Dim strSQL As String
    6.         Dim strConn As String
    7.         Dim intID As Integer
    8.  
    9.         intID = CType(ListBox1.SelectedItem, ListItemNumeric).ID
    10.         dr = ds.Tables("Products").Rows.Find(intID)
    11.  
    12.         dr.BeginEdit()
    13.  
    14.  
    15.         dr("ProductName") = txtName.Text
    16.         dr("SupplierID") = CType(cboSupplier.SelectedItem, ListItemNumeric).ID
    17.         'dr("SupplierID") = CInt(cboSupplier.SelectedIndex + 1)
    18.  
    19.  
    20.         dr("CategoryID") = CType(cboCategory.SelectedItem, ListItemNumeric).ID
    21.         dr("QuantityPerUnit") = txtQty.Text
    22.         dr("UnitPrice") = CDec(txtPrice.Text)
    23.         dr("UnitsInStock") = CShort(txtInStock.Text)
    24.         dr("UnitsOnOrder") = CShort(txtOnOrder.Text)
    25.         dr("ReorderLevel") = CShort(txtReorder.Text)
    26.         dr("Discontinued") = CBool(chkDisc.Checked)
    27.  
    28.         dr.EndEdit()
    29.  
    30.         Try
    31.             strConn = ConnectStringBuild()
    32.             strSQL = "SELECT * FROM Products"
    33.             da = New SqlClient.SqlDataAdapter(strSQL, strConn)
    34.             cbuild = New SqlClient.SqlCommandBuilder(da)
    35.             da.UpdateCommand = cbuild.GetUpdateCommand()
    36.             da.Update(ds, "Products")
    37.             ds.AcceptChanges()
    38.             da.UpdateCommand.Connection.Close()
    39.             ListLoad() 'ignore this line
    40.  
    41.         Catch ex As Exception
    42.             MessageBox.Show(ex.Message.ToString)
    43.  
    44.         End Try
    45.  
    46.     End Sub

  9. #9
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    hi mendhak! I was checking out the code you posted here and I was just wondering what is the 'ListItemNumeric' in this line?

    intID = CType(ListBox1.SelectedItem, ListItemNumeric).ID

    thanks! and hope you'd reply on this one...this will really help me cause I'm having the same problem. Take care!

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by siomai
    hi mendhak! I was checking out the code you posted here and I was just wondering what is the 'ListItemNumeric' in this line?

    intID = CType(ListBox1.SelectedItem, ListItemNumeric).ID

    thanks! and hope you'd reply on this one...this will really help me cause I'm having the same problem. Take care!
    I refuse to believe you have the same problem! ListItemNumeric is a class I created, which holds a Value, and an ID types, which I basically use to populate my listboxes so that I can "use" these values when I'm running a method of some sort.

    The line of code that you put there takes the Object in the ListBox, and converts it to ListItemNumeric type and then gets its ID out.

  11. #11
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    i see...

    so that means i can't apply your code to my program?

    hmm...could you help me? I can't seem to update my database...

    I'm getting so frustrated already..I use the dataadapter.update(dataset) code which doesn't update my database.

    please help me! thanks!

    here's my code...I'm just trying to edit saved records in my database:

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    Dim dr As DataRow
    Try
    dr.BeginEdit()
    dr = DsCust1.Tables("Customername").NewRow
    dr("CustomerID") = txtCustID.Text
    dr("Customername") = txtCustname.Text
    dr("Address") = txtCustAdd.Text
    dr("Tel") = txtCustTel.Text
    dr("Fax") = txtCustFax.Text
    dr("Attention") = txtCustAtt.Text
    dr.EndEdit()
    daCust1.Update(DsCust1)
    MsgBox("Customer record updated", MsgBoxStyle.OKOnly)
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.OKOnly, "Error")
    End Try

    please help me, mendhak! Take care!

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Did you try something similar to what I posted?

    VB Code:
    1. strConn = 'Your connection string goes here
    2.             strSQL = "SELECT * FROM YOURTABLENAME"
    3. 'da is dimmed as a dataadapter, you may already have one existing... in your case, dacust1
    4.             da = New SqlClient.SqlDataAdapter(strSQL, strConn)
    5. 'cbuild is dimmed as a commandbuilder.  Dim cbuild as SqlClient.SqlCommandBuilder
    6. 'This line below will build your SQL statements...
    7.             cbuild = New SqlClient.SqlCommandBuilder(da)
    8.  
    9.             da.UpdateCommand = cbuild.GetUpdateCommand()
    10.             da.Update(ds, "YOURTABLENAME")
    11.             ds.AcceptChanges()
    12.             da.UpdateCommand.Connection.Close()

    Modify it to suit your program, then post back.

    Don't forget to put it in a Try...Catch block so that you can see the errors, if any.

  13. #13
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    thanks for replying mendhak!

    unfortunately, the code did not update my database and showed no error. But I know I there's something wrong with my coding(or logic )...please bear with me and don't get tired of helping me...

    my case is that i created my data adapter,dataset and connection using the wizard. will that cause me any problem?

    here's my code now... please to check it out! (thanks! thanks! thanks!)

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    Dim dr As DataRow
    Dim strSQL As String
    Dim cbuild As System.Data.OleDb.OleDbCommandBuilder

    Try
    strSQL = "Select * from Customername"
    daCust1 = New System.Data.OleDb.OleDbDataAdapter(strSQL, cn1)

    cbuild = New System.Data.OleDb.OleDbCommandBuilder(daCust1)

    daCust1.UpdateCommand = cbuild.GetUpdateCommand
    daCust1.Update(DsCust1, "Customername")
    DsCust1.AcceptChanges()
    daCust1.UpdateCommand.Connection.Close()
    MsgBox("Record has been updated.", MsgBoxStyle.OKOnly)
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.OKOnly, "Error")
    End Try

    End Sub

  14. #14
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Is your connection opened?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  15. #15
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    hi SeanGrebey! I made my connection using the wizard and I think it's automatically opened,or not? Eitherway, i tried to add cn1.open to may code and it still did not update my database. Please help me...I really don't know what to do now.

    here's my code now:

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    Dim dr As DataRow
    Dim strSQL As String
    Dim cbuild As System.Data.OleDb.OleDbCommandBuilder

    Try
    cn1.Open()
    dr = DsCust1.Tables("Customername").NewRow
    dr("CustomerID") = txtCustID.Text
    dr("Customername") = txtCustname.Text
    dr("Address") = txtCustAdd.Text
    dr("Tel") = txtCustTel.Text
    dr("Fax") = txtCustFax.Text
    dr("Attention") = txtCustAtt.Text
    strSQL = "Select * from Customername"
    daCust1 = New System.Data.OleDb.OleDbDataAdapter(strSQL, cn1)

    cbuild = New System.Data.OleDb.OleDbCommandBuilder(daCust1)

    daCust1.UpdateCommand = cbuild.GetUpdateCommand
    daCust1.Update(DsCust1, "Customername")
    DsCust1.AcceptChanges()
    daCust1.UpdateCommand.Connection.Close()
    MsgBox("Record has been updated.", MsgBoxStyle.OKOnly)
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.OKOnly, "Error")
    End Try

    End Sub

    Hope you could help me! Thanks in advance!

  16. #16
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125

    Smile dataset updated but not updating the database???? Help!!! (Resolved)

    hey guys! I got it already...

    Thanks for all your help...

    I added a code that I got from one of our friends here in vbforums... just tried it and it worked!

    Good day to all!
    Last edited by siomai; Aug 15th, 2004 at 09:15 PM.

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