掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
データセットの数 (ID:124333)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
度々のレス恐れ入ります。 >それなりにプログラムの基礎が出来てる人なら勉強期間2日といったところです。 痛いところをつかれた感じです。VB6約半年、.NET一月半ですが基礎は 全然なってないなと実感しました。偶然にもご指摘の2日間でしたが 以下を作成してみました。 '[新規登録]ボタン Private Sub btnEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEntry.Click If MessageBox.Show("新規登録しますか?", Me.Text, MessageBoxButtons.YesNo, _ MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then '中略…登録画面本体のTableA新規登録処理(開発用ライブラリのクラス等で処理) 'TableAの関連テーブルTableB〜TableKにレコード追加 If Entry_TableB(EntryMode.AddNew) = False Then MessageBox.Show("TableB登録失敗", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information) Return End If '中略…以降Entry_TableKまで実行 MessageBox.Show("登録終了", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub '---------------------------------------------------------------------------------------------------- '[削除]ボタン Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click If MessageBox.Show("削除しますか?", Me.Text, MessageBoxButtons.YesNo, _ MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then '中略…登録画面本体のTableA削除処理(開発用ライブラリのクラス等で処理) 'TableAの関連テーブルTableB〜TableKのレコード削除 If Entry_TableB(EntryMode.Delete) = False Then MessageBox.Show("TableB削除失敗", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information) Return End If '中略…以降Entry_TableKまで実行 MessageBox.Show("削除終了", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub '---------------------------------------------------------------------------------------------------- 'TableBの登録・削除 Private Function Entry_TableB(ByVal syoriMode As ModuleCommon.EntryMode) As Boolean Dim wPath As String = ModuleCommon.Constant.mdbPath Dim wTable As String = "TableB" Dim wAdapter As OleDb.OleDbDataAdapter Dim wDataSet As New DataSet Dim wDataView As New DataView Dim wConnection As New OleDb.OleDbConnection Dim wBuilder As OleDb.OleDbCommandBuilder wConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & wPath wAdapter = New OleDb.OleDbDataAdapter("SELECT " & wTable & ".*" & _ " FROM " & wTable, wConnection) wBuilder = New OleDb.OleDbCommandBuilder(wAdapter) wAdapter.Fill(wDataSet, wTable) wDataView.Table = wDataSet.Tables(wTable) wDataView.RowFilter = "(FIELD01 = " & txtCODE1.Text & ")" & _ "AND (FIELD02 = " & txtCODE2.Text & ")" & _ "AND (FIELD03 = " & txtCODE3.Text & ")" & _ "AND (FIELD04 = " & txtCODE4.Text & ")" If syoriMode = EntryMode.AddNew Then If wDataView.Count > 0 Then MessageBox.Show("コード重複", Me.Text, _ MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Return False Else Dim wAddRec As DataRowView = wDataView.AddNew wAddRec("FIELD01") = txtCODE1.Text wAddRec("FIELD02") = txtCODE2.Text wAddRec("FIELD03") = txtCODE3.Text wAddRec("FIELD04") = txtCODE4.Text wAddRec.EndEdit() wAdapter.Update(wDataSet, wTable) Return True End If ElseIf syoriMode = EntryMode.Delete Then If wDataView.Count > 0 Then Dim i As Integer For i = 0 To wDataView.Count - 1 wDataView.Delete(i) Next wAdapter.Update(wDataSet, wTable) Return True Else MessageBox.Show("該当データなし", Me.Text, _ MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Return False End If End If End Function とりあえずそれっぽく動いてくれてるようですが、何度か wAdapter.Updateの所でエラーが出ました。確認のため裏で MDBを開いて実際のテーブルを参照したりしてたので そのせいでしょうか・・・
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.