billsut Ответов: 4

Обновление базы данных access из datagridview с двумя таблицами данных


У меня есть 2 таблицы в одной базе данных.

tblAircraft-ACID, ACName

tblMaster-MasterID, ACID и многие другие, которые не имеют отношения к моему вопросу.

tblAircraft - это поисковая таблица со всеми перечисленными самолетами. tblMaster является основной таблицей и содержит всю подробную информацию.

У меня есть DataGridView, который имеет несколько столбцов. Столбец 1 - это столбец combobox с именем ACName из tblAircraft. Остальные столбцы - это столбцы текстового поля с данными из tblMaster. Мое приложение работает до тех пор, пока не отобразит все данные, и я могу использовать команду dataadapter update для обновления tblMaster (good) и других обновлений источника данных tblAircraft (bad) с помощью DataGridView. Моя проблема заключается в том, что я хочу кислоты в tblMaster, чтобы быть в курсе кислота в выпадающем списке. Конечно, это не так, потому что он принадлежит источнику данных для tblAircraft. Что я упускаю?

Я потратил много часов, пытаясь понять это. Надеюсь, мое объяснение понятно. Заранее благодарю вас за любую помощь, которую вы можете оказать.


Private Sub cboAC_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cboAC.SelectionChangeCommitted

        dsACGrid = LoadDataSet()

        'Refreshes DataGridView
        If dgvTasks.ColumnCount > 0 Then
            For i As Integer = 0 To dgvTasks.ColumnCount - 1
                dgvTasks.Columns.RemoveAt(0)
            Next
        End If

        'Connection obj to database
        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        Dim cbColumn As New DataGridViewComboBoxColumn With
            {
                .DataPropertyName = "ACName",
                .DataSource = dsACGrid.Tables(1),
                .DisplayMember = "ACName",
                .DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
                .Name = "cbColumn",
                .HeaderText = "Aircraft",
                .SortMode = DataGridViewColumnSortMode.NotSortable,
                .ValueMember = "ACName"
            }

        dgvTasks.Columns.Insert(0, cbColumn)

        Dim GSTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "GSTask", .HeaderText = "Gen Spt Task"}

        Dim LCOMTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "LCOMTask", .HeaderText = "LCOM Task"}

        Dim AFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "AFSC", .HeaderText = "AFSC"}

        Dim ReqSkill As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqSkill", .HeaderText = "Req Skill"}

        Dim ReqGrade As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqGrade", .HeaderText = "Req Grade"}

        Dim NotesQuestions As New DataGridViewTextBoxColumn With {.DataPropertyName = "NotesQuestions", .HeaderText = "Notes/Questions"}

        Dim AvgTimeHours As New DataGridViewTextBoxColumn With {.DataPropertyName = "AvgTimeHours", .HeaderText = "Avg Time-Hours"}

        Dim CrewSizeMin As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMin", .HeaderText = "Crew Size Min"}

        Dim CrewSizeMax As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMax", .HeaderText = "Crew Size Max"}

        Dim Manhours As New DataGridViewTextBoxColumn With {.DataPropertyName = "Manhours", .HeaderText = "Manhours"}

        Dim FreqQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqQty", .HeaderText = "Freq Qty"}

        Dim FreqRate As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqRate", .HeaderText = "Freq Rate"}

        Dim PAFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSC", .HeaderText = "PAFSC"}

        Dim PAFSCQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSCQty", .HeaderText = "PAFSC Qty"}

        Dim AltAFSC1 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1", .HeaderText = "Alt AFSC1"}

        Dim AltAFSC1Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1Qty", .HeaderText = "Alt AFSC1 Qty"}

        Dim AltAFSC2 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2", .HeaderText = "Alt AFSC2"}

        Dim AltAFSC2Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2Qty", .HeaderText = "Alt AFSC2 Qty"}

        Dim AltAFSC3 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3", .HeaderText = "Alt AFSC3"}

        Dim AltAFSC3Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3Qty", .HeaderText = "Alt AFSC3 Qty"}

        Dim AltAFSC4 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4", .HeaderText = "Alt AFSC4"}

        Dim AltAFSC4Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4Qty", .HeaderText = "Alt AFSC4 Qty"}

        Dim ACSelected As New DataGridViewCheckBoxColumn With {.DataPropertyName = "ACSelected", .HeaderText = "Selected"}

        With dgvTasks
            .AutoGenerateColumns = False
            .Columns.AddRange(New DataGridViewColumn() {GSTask, LCOMTask, AFSC, 
                  ReqSkill, ReqGrade, NotesQuestions, AvgTimeHours, CrewSizeMin, 
                  CrewSizeMax, Manhours, FreqQty, FreqRate, PAFSC, PAFSCQty, AltAFSC1, 
                  AltAFSC1Qty, AltAFSC2, AltAFSC2Qty, AltAFSC3, AltAFSC3Qty, AltAFSC4, 
                  AltAFSC4Qty, ACSelected})
        End With

        'Bind the dataset after all operation to the datagrid
        dgvTasks.DataSource = dsACGrid.Tables(0)


    End Sub


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        'Loads dropdown for aircraft type
        Dim strSQL As String = "Select * from tblAircraft"

        Dim daAC As OleDbDataAdapter = New OleDbDataAdapter(strSQL, Conn)

        daAC.Fill(dsAC, "tblAircaft")

        Dim dr As DataRow = dsAC.Tables(0).NewRow()
        dr("ACName") = ""
        dsAC.Tables(0).Rows.InsertAt(dr, 0)

        Using cmd As New OleDbCommand(strSQL, Conn)
            With cboAC
                .DataSource = dsAC.Tables(0)
                .DisplayMember = "ACName"
                .ValueMember = "ACName"
            End With
        End Using

        dsAC.Tables.RemoveAt(0)

    End Sub

    Private Function LoadDataSet() As DataSet

        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        'This code refreshes the datasets and data tables.
        If dtACGrid.Rows.Count > 0 Then
            dsACGrid.Tables.RemoveAt(0)
            dtACGrid.Clear()
        End If

        If dtAircraft.Rows.Count > 0 Then
            dsACGrid.Tables.RemoveAt(0)
            dtAircraft.Clear()
        End If

        dsACGrid.Tables.Add(dtACGrid)

        'Load Master table
        strACGrid = "select * from tblMaster where ACName = '" & cboAC.SelectedValue & "'"

        daACGrid = New OleDbDataAdapter(strACGrid, Conn)
        cbACGrid = New OleDbCommandBuilder(daACGrid)

        cbACGrid.QuotePrefix = "["
        cbACGrid.QuoteSuffix = "]"

        daACGrid.Fill(dtACGrid)

        dsACGrid.Tables.Add(dtAircraft)

        'Load Aircraft table
        strACGrid = "select * from tblAircraft"

        daACGrid = New OleDbDataAdapter(strACGrid, Conn)
        cbACGrid = New OleDbCommandBuilder(daACGrid)

        cbACGrid.QuotePrefix = "["
        cbACGrid.QuoteSuffix = "]"

        daACGrid.Fill(dtAircraft)

        Return dsACGrid

    End Function

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

        daACGrid.Update(dtACGrid)
        Me.Close()

    End Sub


End Class


Что я уже пробовал:

Я пробовал использовать связанные и несвязанные столбцы. Это были дни со всеми хитростями, которые я пробовал.

Richard Deeming

Репост
Вы уже опубликовали это на форуме Visual Basic:
https://www.codeproject.com/Messages/5441217/DataGridView-with-Two-Datatables-and-Combobox-Look.aspx[^]

4 Ответов

Рейтинг:
29

billsut

Я получил некоторую помощь на другом форуме и, наконец, получил ее разрешение. Вот окончательный код, если он может помочь кому-то еще.

Public Class Form1

    Dim strACGrid As String = ""
    Dim strSQL As String = ""
    Dim dsACGrid As New DataSet
    Dim dsAircraft As New DataSet
    Dim dsAC As New DataSet
    Dim dtACGrid As New DataTable
    Dim dtAircraft As New DataTable
    Dim daACGrid As OleDbDataAdapter
    Dim daAircraft As OleDbDataAdapter
    Dim cbACGrid As OleDbCommandBuilder
    Dim Conn As New OleDbConnection
    Private Sub cboAC_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cboAC.SelectionChangeCommitted

        dsACGrid = LoadDataSet()

        'Refreshes DataGridView
        If dgvTasks.ColumnCount > 0 Then
            For i As Integer = 0 To dgvTasks.ColumnCount - 1
                dgvTasks.Columns.RemoveAt(0)
            Next
        End If

        'Connection obj to database
        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        Dim cbColumn As New DataGridViewComboBoxColumn With
            {
                .DataPropertyName = "ACID",
                .DataSource = dsACGrid.Tables(1),
                .DisplayMember = "ACName",
                .DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
                .Name = "cbColumn",
                .HeaderText = "Aircraft",
                .SortMode = DataGridViewColumnSortMode.NotSortable,
                .ValueMember = "ACID"
            }

        dgvTasks.Columns.Insert(0, cbColumn)

        Dim GSTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "GSTask", .HeaderText = "Gen Spt Task"}

        Dim LCOMTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "LCOMTask", .HeaderText = "LCOM Task"}

        Dim AFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "AFSC", .HeaderText = "AFSC"}

        Dim ReqSkill As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqSkill", .HeaderText = "Req Skill"}

        Dim ReqGrade As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqGrade", .HeaderText = "Req Grade"}

        Dim NotesQuestions As New DataGridViewTextBoxColumn With {.DataPropertyName = "NotesQuestions", .HeaderText = "Notes/Questions"}

        Dim AvgTimeHours As New DataGridViewTextBoxColumn With {.DataPropertyName = "AvgTimeHours", .HeaderText = "Avg Time-Hours"}

        Dim CrewSizeMin As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMin", .HeaderText = "Crew Size Min"}

        Dim CrewSizeMax As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMax", .HeaderText = "Crew Size Max"}

        Dim Manhours As New DataGridViewTextBoxColumn With {.DataPropertyName = "Manhours", .HeaderText = "Manhours"}

        Dim FreqQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqQty", .HeaderText = "Freq Qty"}

        Dim FreqRate As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqRate", .HeaderText = "Freq Rate"}

        Dim PAFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSC", .HeaderText = "PAFSC"}

        Dim PAFSCQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSCQty", .HeaderText = "PAFSC Qty"}

        Dim AltAFSC1 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1", .HeaderText = "Alt AFSC1"}

        Dim AltAFSC1Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1Qty", .HeaderText = "Alt AFSC1 Qty"}

        Dim AltAFSC2 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2", .HeaderText = "Alt AFSC2"}

        Dim AltAFSC2Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2Qty", .HeaderText = "Alt AFSC2 Qty"}

        Dim AltAFSC3 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3", .HeaderText = "Alt AFSC3"}

        Dim AltAFSC3Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3Qty", .HeaderText = "Alt AFSC3 Qty"}

        Dim AltAFSC4 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4", .HeaderText = "Alt AFSC4"}

        Dim AltAFSC4Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4Qty", .HeaderText = "Alt AFSC4 Qty"}

        Dim ACSelected As New DataGridViewCheckBoxColumn With {.DataPropertyName = "ACSelected", .HeaderText = "Selected"}

        With dgvTasks
            .AutoGenerateColumns = False
            .Columns.AddRange(New DataGridViewColumn() {GSTask, LCOMTask, AFSC, ReqSkill, ReqGrade, NotesQuestions,
                                                       AvgTimeHours, CrewSizeMin, CrewSizeMax, Manhours, FreqQty, FreqRate,
                                                       PAFSC, PAFSCQty, AltAFSC1, AltAFSC1Qty, AltAFSC2, AltAFSC2Qty,
                                                       AltAFSC3, AltAFSC3Qty, AltAFSC4, AltAFSC4Qty, ACSelected})
        End With

        'Bind the dataset to the datagrid
        dgvTasks.DataSource = dsACGrid.Tables(0)


    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        'Loads dropdown for aircraft type to fill DataGridView
        Dim strSQL As String = "Select * from tblAircraft"

        Dim daAC As OleDbDataAdapter = New OleDbDataAdapter(strSQL, Conn)

        daAC.Fill(dsAC, "tblAircaft")

        Dim dr As DataRow = dsAC.Tables(0).NewRow()
        dr("ACName") = ""
        dsAC.Tables(0).Rows.InsertAt(dr, 0)

        Using cmd As New OleDbCommand(strSQL, Conn)
            With cboAC
                .DataSource = dsAC.Tables(0)
                .DisplayMember = "ACName"
                .ValueMember = "ACID"
            End With
        End Using

        dsAC.Tables.RemoveAt(0)

    End Sub

    Private Function LoadDataSet() As DataSet

        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        'This code refreshes the datasets and data tables.
        If dtACGrid.Rows.Count > 0 Then
            dsACGrid.Tables.RemoveAt(0)
            dtACGrid.Clear()
        End If

        If dtAircraft.Rows.Count > 0 Then
            dsACGrid.Tables.RemoveAt(0)
            dtAircraft.Clear()
        End If

        dsACGrid.Tables.Add(dtACGrid)

        'Load Master table
        strACGrid = "select * from tblMaster where ACID = " & cboAC.SelectedValue

        daACGrid = New OleDbDataAdapter(strACGrid, Conn)
        cbACGrid = New OleDbCommandBuilder(daACGrid)

        cbACGrid.QuotePrefix = "["
        cbACGrid.QuoteSuffix = "]"

        daACGrid.Fill(dtACGrid)

        dsACGrid.Tables.Add(dtAircraft)

        'Load Aircraft table
        strACGrid = "select * from tblAircraft"

        daAircraft = New OleDbDataAdapter(strACGrid, Conn)
        cbACGrid = New OleDbCommandBuilder(daACGrid)

        cbACGrid.QuotePrefix = "["
        cbACGrid.QuoteSuffix = "]"

        daAircraft.Fill(dtAircraft)

        Return dsACGrid

    End Function

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

        daACGrid.Update(dtACGrid)
        Me.Close()

    End Sub


End Class


Рейтинг:
2

billsut

Мне удалось заставить combobox работать, но теперь обновление dataadapter не работает. Я получаю сообщение об ошибке "отсутствует ACName для datacolumn '' в DataTable 'Таблица1' для ACName на свойство sourcecolumn''. Вот мой обновленный код:

    Private Sub cboAC_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cboAC.SelectionChangeCommitted

        dsACGrid = LoadDataSet()

        'Refreshes DataGridView
        If dgvTasks.ColumnCount > 0 Then
            For i As Integer = 0 To dgvTasks.ColumnCount - 1
                dgvTasks.Columns.RemoveAt(0)
            Next
        End If

        'Connection obj to database
        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        Dim cbColumn As New DataGridViewComboBoxColumn With
            {
                .DataPropertyName = "ACID",
                .DataSource = dsACGrid.Tables(1),
                .DisplayMember = "ACName",
                .DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
                .Name = "cbColumn",
                .HeaderText = "Aircraft",
                .SortMode = DataGridViewColumnSortMode.NotSortable,
                .ValueMember = "ACID"
            }

        dgvTasks.Columns.Insert(0, cbColumn)

        Dim GSTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "GSTask", .HeaderText = "Gen Spt Task"}

        Dim LCOMTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "LCOMTask", .HeaderText = "LCOM Task"}

        Dim AFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "AFSC", .HeaderText = "AFSC"}

        Dim ReqSkill As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqSkill", .HeaderText = "Req Skill"}

        Dim ReqGrade As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqGrade", .HeaderText = "Req Grade"}

        Dim NotesQuestions As New DataGridViewTextBoxColumn With {.DataPropertyName = "NotesQuestions", .HeaderText = "Notes/Questions"}

        Dim AvgTimeHours As New DataGridViewTextBoxColumn With {.DataPropertyName = "AvgTimeHours", .HeaderText = "Avg Time-Hours"}

        Dim CrewSizeMin As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMin", .HeaderText = "Crew Size Min"}

        Dim CrewSizeMax As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMax", .HeaderText = "Crew Size Max"}

        Dim Manhours As New DataGridViewTextBoxColumn With {.DataPropertyName = "Manhours", .HeaderText = "Manhours"}

        Dim FreqQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqQty", .HeaderText = "Freq Qty"}

        Dim FreqRate As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqRate", .HeaderText = "Freq Rate"}

        Dim PAFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSC", .HeaderText = "PAFSC"}

        Dim PAFSCQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSCQty", .HeaderText = "PAFSC Qty"}

        Dim AltAFSC1 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1", .HeaderText = "Alt AFSC1"}

        Dim AltAFSC1Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1Qty", .HeaderText = "Alt AFSC1 Qty"}

        Dim AltAFSC2 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2", .HeaderText = "Alt AFSC2"}

        Dim AltAFSC2Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2Qty", .HeaderText = "Alt AFSC2 Qty"}

        Dim AltAFSC3 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3", .HeaderText = "Alt AFSC3"}

        Dim AltAFSC3Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3Qty", .HeaderText = "Alt AFSC3 Qty"}

        Dim AltAFSC4 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4", .HeaderText = "Alt AFSC4"}

        Dim AltAFSC4Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4Qty", .HeaderText = "Alt AFSC4 Qty"}

        Dim ACSelected As New DataGridViewCheckBoxColumn With {.DataPropertyName = "ACSelected", .HeaderText = "Selected"}

        With dgvTasks
            .AutoGenerateColumns = False
            .Columns.AddRange(New DataGridViewColumn() {GSTask, LCOMTask, AFSC, ReqSkill, ReqGrade, NotesQuestions,
                                                       AvgTimeHours, CrewSizeMin, CrewSizeMax, Manhours, FreqQty, FreqRate,
                                                       PAFSC, PAFSCQty, AltAFSC1, AltAFSC1Qty, AltAFSC2, AltAFSC2Qty,
                                                       AltAFSC3, AltAFSC3Qty, AltAFSC4, AltAFSC4Qty, ACSelected})
        End With

        'Bind the dataset to the datagrid
        dgvTasks.DataSource = dsACGrid.Tables(0)


    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        'Loads dropdown for aircraft type to fill DataGridView
        Dim strSQL As String = "Select * from tblAircraft"

        Dim daAC As OleDbDataAdapter = New OleDbDataAdapter(strSQL, Conn)

        daAC.Fill(dsAC, "tblAircaft")

        Dim dr As DataRow = dsAC.Tables(0).NewRow()
        dr("ACName") = ""
        dsAC.Tables(0).Rows.InsertAt(dr, 0)

        Using cmd As New OleDbCommand(strSQL, Conn)
            With cboAC
                .DataSource = dsAC.Tables(0)
                .DisplayMember = "ACName"
                .ValueMember = "ACID"
            End With
        End Using

        dsAC.Tables.RemoveAt(0)

    End Sub

    Private Function LoadDataSet() As DataSet

        Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"

        'This code refreshes the datasets and data tables.
        If dtACGrid.Rows.Count > 0 Then
            dsACGrid.Tables.RemoveAt(0)
            dtACGrid.Clear()
        End If

        If dtAircraft.Rows.Count > 0 Then
            dsACGrid.Tables.RemoveAt(0)
            dtAircraft.Clear()
        End If

        dsACGrid.Tables.Add(dtACGrid)

        'Load Master table
        strACGrid = "select * from tblMaster where ACID = " & cboAC.SelectedValue

        daACGrid = New OleDbDataAdapter(strACGrid, Conn)
        cbACGrid = New OleDbCommandBuilder(daACGrid)

        cbACGrid.QuotePrefix = "["
        cbACGrid.QuoteSuffix = "]"

        daACGrid.Fill(dtACGrid)

        dsACGrid.Tables.Add(dtAircraft)

        'Load Aircraft table
        strACGrid = "select * from tblAircraft"

        daACGrid = New OleDbDataAdapter(strACGrid, Conn)
        cbACGrid = New OleDbCommandBuilder(daACGrid)

        cbACGrid.QuotePrefix = "["
        cbACGrid.QuoteSuffix = "]"

        daACGrid.Fill(dtAircraft)

        Return dsACGrid

    End Function

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

        daACGrid.Update(dtACGrid)
        Me.Close()

    End Sub


End Class


Richard Deeming

Это решение вашего вопроса? Текст в начале заставляет думать, что это должно быть обновление вашего вопроса.

Но вы приняли это как решение вашей проблемы, поэтому ваш вопрос теперь "решен".

Рейтинг:
0

CyberSaint

Воспользоваться ссылкой из tblmaster таблице

tblAircraft
и на обновления изменения selectionindex выпадающий список БД.. через идентификатор.


CHill60

Я уже давно здесь и не могу понять вашего ответа, так что подозреваю, что и ОП тоже не поймет. Используйте ссылку улучшить решение и сделайте это более понятным

Рейтинг:
0

billsut

Я согласен с CHill60. Пожалуйста, используйте полные предложения и ДОУ, на какие строки моего кода Вы ссылаетесь и какие изменения конкретно предлагаете. Спасибо за помощь.

Я также хотел разместить здесь фотографию моего DataGridView для уточнения, но я не вижу способа сделать это. Кто - нибудь знает, как?


Richard Deeming

Если вы хотите прокомментировать решение, нажмите кнопку "есть вопрос или комментарий?" кнопка под этим решением.

НЕ оставьте свой комментарий как новое решение!