We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Add Data to DB using datagridview

tobin46 asked
Medium Priority
Last Modified: 2012-05-11
Looking for guidance on how to add data to my database using four data grid views.

I have one form.  There is a header section, then a tab control with 4 tabs, each tab having a datgridview.  The header info is on one table, and each tab's datagridview ties to one table.  

Below is the code I'm using for the datagridviews.  When the form loads, each tab control is returning with data because I am filling the DataTables.  I understand that.  How could I modify this code so that the form loads, I can enter data in each tab's datagridview and then save to the database?  I might be way off....

        Dim Labor_Info_SQL As String = "SELECT * FROM Labor"
        Dim Material_Info_SQL As String = "SELECT * FROM Material"
        Dim Equipment_Info_SQL As String = "SELECT * FROM Equipment"
        Dim Subcontractor_Info_SQL As String = "SELECT * FROM Subcontractor"

        DA_Labor_Info = New SqlDataAdapter(Labor_Info_SQL, My.Settings.IEC_DB_Connection)
        Dim Labor_Command_Builder As New SqlCommandBuilder(DA_Labor_Info)
        Dim dt_Labor_Info As New DataTable

        DA_Material_Info = New SqlDataAdapter(Material_Info_SQL, My.Settings.IEC_DB_Connection)
        Dim Material_Command_Builder As New SqlCommandBuilder(DA_Material_Info)
        Dim dt_Material_Info As New DataTable

        DA_Equipment_Info = New SqlDataAdapter(Equipment_Info_SQL, My.Settings.IEC_DB_Connection)
        Dim Equipment_Command_Builder As New SqlCommandBuilder(DA_Equipment_Info)
        Dim dt_Equipment_Info As New DataTable

        DA_Subcontractor_Info = New SqlDataAdapter(Subcontractor_Info_SQL, My.Settings.IEC_DB_Connection)
        Dim Subcontractor_Command_Builder As New SqlCommandBuilder(DA_Subcontractor_Info)
        Dim dt_Subcontractor_Info As New DataTable


            DA_Labor_Info.FillSchema(dt_Labor_Info, SchemaType.Source)
            Me.DG_Labor_Binding.DataSource = dt_Labor_Info

            DA_Material_Info.FillSchema(dt_Material_Info, SchemaType.Source)
            Me.DG_Material_Binding.DataSource = dt_Material_Info

            DA_Equipment_Info.FillSchema(dt_Equipment_Info, SchemaType.Source)
            Me.DG_Equipment_Binding.DataSource = dt_Equipment_Info

            DA_Subcontractor_Info.FillSchema(dt_Subcontractor_Info, SchemaType.Source)
            Me.DG_Subcontractor_Binding.DataSource = dt_Subcontractor_Info


        Catch ex As Exception

            Throw ex

        End Try

    End Sub

Watch Question

Senior Software Engineer
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.