[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Add Data to DB using datagridview

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


        Try

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

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

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

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

            'Me.Set_Up_Data_Grids()

        Catch ex As Exception

            Throw ex

        End Try

    End Sub

0
tobin46
Asked:
tobin46
1 Solution
 
Mohamed AbowardaSoftware EngineerCommented:
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now