14 Replies - 338 Views - Last Post: 19 February 2019 - 08:09 PM Rate Topic: -----

#1 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Unable to save and update mysql db using datagridview

Posted 17 February 2019 - 08:31 PM

I am using a winform which is linked to a MySQL database. I have updated my code. My form has textboxes, a combobox, a checkbox and a datagridview. The end goal is to update, add new records and save changes back to MySQL database.

When I click on a row in the datagridview (say record 7) and I then make an update the quantity textbox for record 7, and I click the update button, it throws an exception message:-

exception thrown 'system.invalidoperationexception' in system.data.dll (the SelectCommand property has not been initilalized before calling Fill vba.net


My vba.net code is: -
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
daOrders = New MySqlDataAdapter("SELECT * FROM Orders", MysqlConn)
        daOrders.MissingSchemaAction = MissingSchemaAction.AddWithKey
        Dim dsOrders As New DataSet
        dtOrders = New DataTable("Orders")
        daOrders.Fill(dtOrders)
        dsOrders.Tables.Add(dtOrders)
        Dim cbOrders As New MySqlCommandBuilder(daOrders)
        daProducts = New MySqlDataAdapter("SELECT * FROM Products", MysqlConn)
        dtProducts = New DataTable("Products")
        daProducts.Fill(dtProducts)
        dsOrders.Tables.Add(dtProducts)
        cbOrders = New MySqlCommandBuilder(daProducts)

        dtOrders.Columns("MetricID").AutoIncrement = True
        dtProducts.Columns("ProductID").AutoIncrement = True

        dtOrders.Columns(0).AutoIncrementSeed = dtProducts.Rows.Cast(Of DataRow).Max(Function(dr As DataRow) CInt(dr.Item(0))) + 1
        dtProducts.Columns(0).AutoIncrementStep = 1

        dtProducts.Columns(0).AutoIncrementSeed = dtProducts.Rows.Cast(Of DataRow).Max(Function(dr) CInt(dr.Item(0))) + 1
        dtProducts.Columns(0).AutoIncrementStep = 1

        dsOrders.Relations.Add(New DataRelation("relation", dsOrders.Tables("Products").Columns("ProductID"), dsOrders.Tables("Orders").Columns("ProductID_fk")))

        ProductBindingSource = New BindingSource(dsOrders, "Products")

        CboProductID_fk.DisplayMember = "Product"
        CboProductID_fk.ValueMember = "ProductID"
        CboProductID_fk.DataSource = ProductBindingSource

        OrderBindingSource = New BindingSource(ProductBindingSource, "relation")

        'bind the Product's foreign key to the combobox's "SelectedValue"
        Me.CboProductID_fk.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.OrderBindingSource, "ProductID_fk", True))

        'Bind the DataTable to the UI via a BindingSource.
        OrderBindingSource.DataSource = dtOrders
        Me.OrderBindingNavigator.BindingSource = Me.OrderBindingSource

        txtMetricID.DataBindings.Add("Text", Me.OrderBindingSource, "MetricID")
        txtOrders.DataBindings.Add("Text", Me.OrderBindingSource, "Orders")
        ChkCheckedStatus.DataBindings.Add("Text", Me.OrderBindingSource, "CheckedStatus")
        txtOrderQuantity.DataBindings.Add("Text", Me.OrderBindingSource, "Quantity")

        ' Bind the DataGridView to the BindingSource
        ' and load the data from the database.

        OrderBindingSource.DataSource = OrderDataGridView.Rows
        OrderBindingNavigator.BindingSource = OrderBindingSource
        Me.OrderDataGridView.DataSource = Me.OrderBindingSource
        GetOrderData("select * from Orders")

        'instead of adding event handler for MoveFirst,MoveLast,MoveNext,MovePrevious
        'chose this one. it will fire anyway
        AddHandler BindingNavigatorPositionItem.TextChanged, AddressOf bindingnavigator_Postionchanged


  'if it didn't find the key, position = 1
        'you can also try any else proper event
OrderBindingSource.Position = OrderBindingSource.Find("MetricID", IIf(txtMetricID.Text = "", 0, txtMetricID.Text))
End Sub

Private Sub UpdateOrders()
        Dim conn As New MySqlConnection
        conn.ConnectionString =
       "server=localhost;Port=3306;database=database;userid=root;password=password;persistsecurityinfo=True"
        Dim daOrders As MySqlDataAdapter = New MySqlDataAdapter("SELECT * From Orders", conn)
        Dim myBuilder = New MySqlCommandBuilder(daOrders)
        conn.Open()
        daOrders.Fill(dsOrders, "Orders")
        daOrders.Update(dsOrders, "Orders")
        MsgBox("Data Updated", MsgBoxStyle.OkOnly)

        With CboProductID_fk
            .DisplayMember = "Product"
            .ValueMember = "ProductID"
            .DataSource = OrderBindingSource
        End With


        txtOrders.DataBindings.Clear()
        ChkCheckedStatus.DataBindings.Clear()
        txtOrderQuantity.DataBindings.Clear()

        OrderBindingNavigator.BindingSource = OrderBindingSource

        With Me
            .txtOrders.DataBindings.Add("Text", OrderBindingSource, "Orders", True, DataSourceUpdateMode.OnValidation, vbNullString)
            .ChkCheckedStatus.DataBindings.Add("CheckState", OrderBindingSource, "CheckedStatus", True, DataSourceUpdateMode.OnValidation, CheckState.Unchecked)
            .txtOrderQuantity.DataBindings.Add("Text", OrderBindingSource, "Quantity", True, DataSourceUpdateMode.OnValidation, vbNullString)
        End With

        OrderBindingSource.EndEdit()
        daOrders.Update(dtOrders)
End Sub
Private Sub DgvOrders()
        con = New MySqlConnection
        con.ConnectionString = conString
        Dim MySqldaOrders As New MySqlDataAdapter
        Dim OrdersBindingSource As New BindingSource
        Try
            con.Open()
            Dim queryOrders As String = "select * from database.Orders"
            cmd = New MySqlCommand(queryOrders, con)
            MySqldaOrders.Fill(dtOrders)
            OrdersBindingSource.DataSource = dtOrders
            OrderDataGridView.DataSource = OrderBindingSource
            MySqldaOrders.Update(dtOrders)

            con.Close()

        Catch ex As Exception

        End Try
    End Sub
Private Sub BtnProductUpdate_Click(sender As Object, e As EventArgs) Handles BtnProductUpdate.Click

        UpdateOrders()
        DgvOrders()

        
    End Sub


Private Sub BtnOrderSave_Click(sender As Object, e As EventArgs) Handles BtnOrderSave.Click
        Dim dsOrders As New DataSet
        Me.Validate()

        Me.OrderBindingSource.EndEdit()

        Me.daOrders.Update(dsOrders, "Orders")

End Sub


Another problem which I am experiencing is if I add a record, using the binding navigator new record control and I fill in the details of the new record and click the save button, the following error message occurs: -
System.InvalidOperationException: 'Update unable to find TableMapping['Orders'] or DataTable 'Orders'.'


Is This A Good Question/Topic? 0
  • +

Replies To: Unable to save and update mysql db using datagridview

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14859
  • View blog
  • Posts: 59,283
  • Joined: 12-June 08

Re: Unable to save and update mysql db using datagridview

Posted 17 February 2019 - 08:52 PM

What lines are the errors happening on?
Was This Post Helpful? 0
  • +
  • -

#3 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 18 February 2019 - 07:28 AM

Hello,

The first error is shown below:


exception thrown 'system.invalidoperationexception' in system.data.dll (the SelectCommand property has not been initilalized before calling Fill vba.net 


This first error occurred with this section of vba.net code: -
Dim MySqldaOrders As New MySqlDataAdapter
        Dim OrdersBindingSource As New BindingSource
        Try
            con.Open()
            Dim queryOrders As String = "select * from database.Orders"
            cmd = New MySqlCommand(queryOrders, con)
            MySqldaOrders.Fill(dtOrders)


The second error below: -

System.InvalidOperationException: 'Update unable to find TableMapping['Orders'] or DataTable 'Orders'.' 


and this second error message occurred at this line of code: -

Me.daOrders.Update(dsOrders, "Orders")

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is online

  • Stealth IT
  • member icon

Reputation: 6744
  • View blog
  • Posts: 27,758
  • Joined: 12-December 12

Re: Unable to save and update mysql db using datagridview

Posted 18 February 2019 - 07:46 AM

Is "database.Orders" correct? That is, is your schema named "database"?

From the small snippet you have posted, there is no connection between 'cmd' and the Fill() call. Possibly could be set with MySqldaOrders.SelectCommand = cmd.

The second error probably follows from the first.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14859
  • View blog
  • Posts: 59,283
  • Joined: 12-June 08

Re: Unable to save and update mysql db using datagridview

Posted 18 February 2019 - 08:07 AM

You keep using 'vba.net'. Do you mean VB.NET or is this something in excel or access where VBA is prevalent?
Was This Post Helpful? 0
  • +
  • -

#6 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 18 February 2019 - 08:35 AM

View Postmodi123_1, on 18 February 2019 - 08:07 AM, said:

You keep using 'vba.net'. Do you mean VB.NET or is this something in excel or access where VBA is prevalent?


Apologies, I mean VB.NET.
Was This Post Helpful? 0
  • +
  • -

#7 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 18 February 2019 - 03:41 PM

View Postandrewsw, on 18 February 2019 - 07:46 AM, said:

Is "database.Orders" correct? That is, is your schema named "database"?

From the small snippet you have posted, there is no connection between 'cmd' and the Fill() call. Possibly could be set with MySqldaOrders.SelectCommand = cmd.

The second error probably follows from the first.


Hi andrewsw,

My schema name is not actually called "database".

Thank you for your response. I will the changes on and report back if I have any issues.
Was This Post Helpful? 0
  • +
  • -

#8 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 18 February 2019 - 08:50 PM

I updated this section of VB.NET code

  Private Sub DgvOrders()
        con = New MySqlConnection
        con.ConnectionString = conString
        Dim MySqldaOrders As New MySqlDataAdapter
        Dim OrdersBindingSource As New BindingSource
        Try
            con.Open()
            Dim queryOrders As String = "select * from Orders"
            cmd = New MySqlCommand(queryOrders, con)
            MySqldaOrders.SelectCommand = cmd
            MySqldaOrders.Fill(dtOrders)
            OrdersBindingSource.DataSource = dtOrders
            OrderDataGridView.DataSource = OrderBindingSource
            MySqldaOrders.Update(dtOrders)

            con.Close()

        Catch ex As Exception

        End Try
    End Sub



MySqldaOrders.SelectCommand = cmd.


after the line
 cmd = New MySqlCommand(queryOrders, con)


when I built the solution and I press the update button, the message dialog box appeared and indicated that the update was successfully. However, the combobox's text data (e.g. Product1) immediately disappeared and it was replaced and filled by this phrase "system.data.datarowview (when I press the combobox's dropdown button, there were 23 rows of the phrase "system.data.datarowview").

So I updated this VB.NET code again as follows:-

   Private Sub UpdateOrders()
MysqlConn = New MySqlConnection
        con.ConnectionString = "Server=localhost;Port=3306;Database=database;userid=root;password=password;persist security info=True"
        Dim MySqldaOrders As New MySqlDataAdapter
        daOrders.SelectCommand.Connection = MysqlConn
        MysqlConn.Open()
        daOrders.SelectCommand.CommandText = "Select * From Orders"
        daOrders = New MySqlDataAdapter("SELECT * FROM Orders", MysqlConn)
        daOrders.MissingSchemaAction = MissingSchemaAction.AddWithKey
            Dim dsOrders As New DataSet
            dtOrders = New DataTable("Orders")
            daOrders.Fill(dtOrders)
            dsOrders.Tables.Add(dtOrders)
            Dim cbOrders As New MySqlCommandBuilder(daOrders)
            daProducts = New MySqlDataAdapter("SELECT * FROM Products", MysqlConn)
            dtProducts = New DataTable("Products")
            daProducts.Fill(dtProducts)
            dsOrders.Tables.Add(dtProducts)
            cbOrders = New MySqlCommandBuilder(daProducts)

            dtOrders.Columns("MetricID").AutoIncrement = True
            dtProducts.Columns("ProductID").AutoIncrement = True

            dtOrders.Columns(0).AutoIncrementSeed = dtProducts.Rows.Cast(Of DataRow).Max(Function(dr As DataRow) CInt(dr.Item(0))) + 1
            dtProducts.Columns(0).AutoIncrementStep = 1

            dtProducts.Columns(0).AutoIncrementSeed = dtProducts.Rows.Cast(Of DataRow).Max(Function(dr) CInt(dr.Item(0))) + 1
            dtProducts.Columns(0).AutoIncrementStep = 1

            dsOrders.Relations.Add(New DataRelation("relation", dsOrders.Tables("Products").Columns("ProductID"), dsOrders.Tables("Orders").Columns("ProductID_fk")))

            ProductBindingSource = New BindingSource(dsOrders, "Products")

            CboProductID_fk.DisplayMember = "Product"
            CboProductID_fk.ValueMember = "ProductID"
            CboProductID_fk.DataSource = ProductBindingSource

            OrderBindingSource = New BindingSource(ProductBindingSource, "relation")

            'bind the Product's foreign key to the combobox's "SelectedValue"
            Me.CboProductID_fk.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.OrderBindingSource, "ProductID_fk", True))

            'Bind the DataTable to the UI via a BindingSource.
            OrderBindingSource.DataSource = dtOrders
            Me.OrderBindingNavigator.BindingSource = Me.OrderBindingSource

        MsgBox("Data Updated", MsgBoxStyle.OkOnly)

        MysqlConn.Close()
        
        OrderBindingSource.EndEdit()
        daOrders.Update(dtOrders)
End Sub




Now, when I build a solution, and I change the textbox data and then press the update button, it shows the following error message:-
MySql.Data.MySqlClient.MySqlException: 'Host '192.168.1.10' is not allowed to connect to this MySQL server' visual studio vb.net


at the line: -

   MysqlConn.Open()

Was This Post Helpful? 0
  • +
  • -

#9 andrewsw   User is online

  • Stealth IT
  • member icon

Reputation: 6744
  • View blog
  • Posts: 27,758
  • Joined: 12-December 12

Re: Unable to save and update mysql db using datagridview

Posted 19 February 2019 - 01:42 AM

Why do you have both con and MysqlConn?
Was This Post Helpful? 0
  • +
  • -

#10 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 19 February 2019 - 04:40 AM

Hi Andrews,

Good catch!No particular reason.I only copied and pasted code from a different section here and I thought that I had changed all of the connection reference. I will modify the connection string name.
Was This Post Helpful? 0
  • +
  • -

#11 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 19 February 2019 - 05:56 AM

Hi andrewsw,

I have changed the names of the connection strings: -

Imports MySql
Imports MySql.Data.MySqlClient
Imports MySql.Data


Public Class Form1
Inherits Form

Dim conString As String = "Server=localhost;Port=3306;Database=mydatabase;userid=root;password=mypassword;persist security info=True"
    Dim con As MySqlConnection = New MySqlConnection(conString)
    Dim adapter As MySqlDataAdapter

Dim conString As String = "Server=localhost;Port=3306;Database=mydatabase;userid=root;password=mypassword;persist security info=True"
    Dim con As MySqlConnection = New MySqlConnection(conString)

Private Sub UpdateOrders()

        con = New MySqlConnection
        con.ConnectionString = conString
        Dim MySqldaOrders As New MySqlDataAdapter
        daOrders.SelectCommand.Connection = con
        con.Open()
        daOrders.SelectCommand.CommandText = "Select * From Orders"
        daOrders = New MySqlDataAdapter("SELECT * FROM Orders", con)
        daOrders.MissingSchemaAction = MissingSchemaAction.AddWithKey
            Dim dsOrders As New DataSet
            dtOrders = New DataTable("Orders")
            daOrders.Fill(dtOrders)
            dsOrders.Tables.Add(dtOrders)
            Dim cbOrders As New MySqlCommandBuilder(daOrders)
        daProducts = New MySqlDataAdapter("SELECT * FROM Products", con)
        dtProducts = New DataTable("Products")
            daProducts.Fill(dtProducts)
            dsOrders.Tables.Add(dtProducts)
            cbOrders = New MySqlCommandBuilder(daProducts)

            dtOrders.Columns("MetricID").AutoIncrement = True
            dtProducts.Columns("ProductID").AutoIncrement = True

            dtOrders.Columns(0).AutoIncrementSeed = dtProducts.Rows.Cast(Of DataRow).Max(Function(dr As DataRow) CInt(dr.Item(0))) + 1
            dtProducts.Columns(0).AutoIncrementStep = 1

            dtProducts.Columns(0).AutoIncrementSeed = dtProducts.Rows.Cast(Of DataRow).Max(Function(dr) CInt(dr.Item(0))) + 1
            dtProducts.Columns(0).AutoIncrementStep = 1

            dsOrders.Relations.Add(New DataRelation("relation", dsOrders.Tables("Products").Columns("ProductID"), dsOrders.Tables("Orders").Columns("ProductID_fk")))

            ProductBindingSource = New BindingSource(dsOrders, "Products")

            CboProductID_fk.DisplayMember = "Product"
            CboProductID_fk.ValueMember = "ProductID"
            CboProductID_fk.DataSource = ProductBindingSource

            OrderBindingSource = New BindingSource(ProductBindingSource, "relation")

        'bind the Product's foreign key to the combobox's "SelectedValue"
        ' Me.CboProductID_fk.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.OrderBindingSource, "ProductID_fk", True))

        'Bind the DataTable to the UI via a BindingSource.
        OrderBindingSource.DataSource = dtOrders
            Me.OrderBindingNavigator.BindingSource = Me.OrderBindingSource

        MsgBox("Data Updated", MsgBoxStyle.OkOnly)

        con.Close()
        

        OrderBindingNavigator.BindingSource = OrderBindingSource


        OrderBindingSource.EndEdit()
        daOrders.Update(dtOrders)

    End Sub
End Class



When I build the solution, make any udpates to the textbox data and press the update button, the dialog message box pops up with the message: "updated successfully". However, when I check the MySQL database to see if the updates have occurred in the table's fields, there are no updates. The visual studio programme is not showing any errors or exceptions when the code is ran.
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw   User is online

  • Stealth IT
  • member icon

Reputation: 6744
  • View blog
  • Posts: 27,758
  • Joined: 12-December 12

Re: Unable to save and update mysql db using datagridview

Posted 19 February 2019 - 06:25 AM

Do you mean it displays your message "Data Updated"? If so then it is reassuring that it makes it that far in the code, although distracting because nothing is being updated(?). Else, where is this updating taking place?

Check the Copy to Output Directory property of the database, it is possible that the database is being updated but replaced each time.
Was This Post Helpful? 0
  • +
  • -

#13 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 19 February 2019 - 10:31 AM

HI andrewsw,

I am not sure how to Check the Copy to Output Directory property of the database. I had googled to see how to do this, by checking my Solution Explorer for the database. My understanding is I should have created a datasource and linked my database to this datasource. Previously, I had tried to do so but I received an error message: "some updating commands could not be generated automatically. The database returned the following error . You have a usuable connection already".

When I checked the files in the Solution Explorer, I see mydatabase.exe. But I do not see the option to Copy to Output Directory.
"
Was This Post Helpful? 0
  • +
  • -

#14 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 19 February 2019 - 03:56 PM

Hi andrewsw,

I looked in Solutions Explorer, under VB:MyDatabase>My Project > VB:Application.myapp. Under the File Properties of Application.Designer.vb, the Copy to Output Directory is set to "Do not copy". Similarly the items under the following directory pathers showed the Copy to Output Directory is set to 'Do not copy':-

VB:MyDatabase>My Project > VB:Application.myapp>Application.Designer.vb
vB:MyDatabase>VB:Assemblyinfo.vb
Was This Post Helpful? 0
  • +
  • -

#15 wire_jp   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 10-January 19

Re: Unable to save and update mysql db using datagridview

Posted 19 February 2019 - 08:09 PM

Hi andrewsw,

I got the issue resolved and I can now save changes to the textbox data back to the MySQL database by using this vb.net code below (thank you for all of your help):-

Imports MySql
Imports MySql.Data.MySqlClient
Imports MySql.Data

Public Class Form1
    Inherits Form

   Public ConnectionString As String = ""
    Dim conString As String = "Server=localhost;Port=3306;Database=mydatabase;userid=root;password=mypassword;persist security info=True"
    Dim con As MySqlConnection = New MySqlConnection(conString)


Private Sub EndEditOnAllBindingSources()
        Dim BindingSourcesQuery = From bindingsources In Me.components.Components
                                  Where (TypeOf bindingsources Is Windows.Forms.BindingSource)
                                  Select bindingsources

        For Each bindingSource As Windows.Forms.BindingSource In BindingSourcesQuery
            bindingSource.EndEdit()
        Next
    End Sub


Private Sub BtnOrderSave_Click(sender As Object, e As EventArgs) Handles BtnOrderSave.Click

        Me.EndEditOnAllBindingSources()

        SaveOrders()

    End Sub

    Private Sub SaveOrders(Optional messages As Boolean = True)

        con = New MySqlConnection
        con.ConnectionString = conString
        Dim daOrders As New MySqlDataAdapter("select * from Orders", con)
        Dim dsOrders As New DataSet

        If Me.Validate Then
            Me.OrderBindingSource.EndEdit()
            Me.daOrders.Update(Me.dtOrders)
            dsOrders.EnforceConstraints = False
        Else
            System.Windows.Forms.MessageBox.Show(Me, "Validation _
                                              errors occurred.",
              "Save", System.Windows.Forms.MessageBoxButtons.OK,
              System.Windows.Forms.MessageBoxIcon.Warning)
        End If

        Try
            dsOrders.EnforceConstraints = True
        Catch e As System.Data.ConstraintException
            ' Process exception and return.
            Console.WriteLine("Exception of type {0} occurred.",
            e.GetType().ToString())
        End Try


    End Sub


Private Sub BtnOrderSave_Click(sender As Object, e As EventArgs) Handles BtnOrderSave.Click

        Me.EndEditOnAllBindingSources()

       SaveOrders()
  End Sub

    Private Sub SaveOrders(Optional messages As Boolean = True)

        con = New MySqlConnection
        con.ConnectionString = conString
        Dim daOrders As New MySqlDataAdapter("select * from Orders", con)
        Dim dsOrders As New DataSet

        If Me.Validate Then
            Me.OrderBindingSource.EndEdit()
            Me.daOrders.Update(Me.dtOrders)
            dsOrders.EnforceConstraints = False
        Else
            System.Windows.Forms.MessageBox.Show(Me, "Validation _
                                              errors occurred.",
              "Save", System.Windows.Forms.MessageBoxButtons.OK,
              System.Windows.Forms.MessageBoxIcon.Warning)
        End If

        Try
            dsOrders.EnforceConstraints = True
        Catch e As System.Data.ConstraintException
            ' Process exception and return.
            Console.WriteLine("Exception of type {0} occurred.",
            e.GetType().ToString())
        End Try


    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1