Add Data to DB using datagridview

Posted on 2011-04-21
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

Question by:tobin46
    1 Comment
    LVL 12

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now