| 8 | 1/1 | 返回列表 |
| 查看: 2330 | 回復: 7 | |||
zzahkj木蟲 (著名寫手)
龍
|
[交流]
【求助】vb.net的DataGridView如何編輯后保存到Access數(shù)據(jù)庫中? 已有2人參與
|
| vb.net的DataGridView如何編輯后保存到數(shù)據(jù)庫中?我現(xiàn)在已經實現(xiàn)數(shù)據(jù)表在DataGridView中顯示了,可隨便對一個單元格進行編輯后卻無法保存到原來的Access數(shù)據(jù)表中,求高手指點,給一段代碼?謝謝! 給段VB代碼也行! |

至尊木蟲 (著名寫手)
驃騎將軍

木蟲 (著名寫手)
龍
|
我是這樣編寫的 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim Adapter As New OleDb.OleDbDataAdapter("Select * From huaxue ", AAADataSet1) Dim Bulid As New OleDb.OleDbCommandBuilder(Adapter) Try shujubiaoadapter.Update(DataGridView1.DataSource) 'Recorder.Update(Dt, "Db " 'Dt.AcceptChanges() Catch ex As Exception Console.WriteLine(ex.Message) MsgBox("數(shù)據(jù)保存失敗! " & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical) Finally shujubiaoadapter.Dispose() Bulid.Dispose() End Try End Sub End Class 然后出現(xiàn)錯誤 1 重載決策失敗,原因是沒有可訪問的“New”可以用這些參數(shù)調用: 'Public Sub New(selectCommandText As String, selectConnection As System.Data.OleDb.OleDbConnection)': 類型“數(shù)據(jù)庫_實驗.AAADataSet1”的值無法轉換為“System.Data.OleDb.OleDbConnection”。 'Public Sub New(selectCommandText As String, selectConnectionString As String)': 類型“數(shù)據(jù)庫_實驗.AAADataSet1”的值無法轉換為“String”。 F:\復件 復件 數(shù)據(jù)庫-實驗oo\畫圖-實驗\Form1.vb 228 13 數(shù)據(jù)庫-實驗 這是怎么回事?該如何解決? |

至尊木蟲 (著名寫手)
驃騎將軍

木蟲 (著名寫手)
龍

至尊木蟲 (著名寫手)
驃騎將軍

木蟲 (著名寫手)
龍
|
Private conn As OleDb.OleDbConnection = Nothing Private comm As OleDb.OleDbCommand = Nothing Private CB As OleDb.OleDbCommandBuilder Private Adapter As OleDb.OleDbDataAdapter Public Sub updataTable(ByVal constr As String, ByVal pubtable As DataTable, ByVal selectformstr As String) conn = New OleDb.OleDbConnection(constr) conn.Open() comm = New OleDb.OleDbCommand Adapter = New OleDb.OleDbDataAdapter comm.Connection = conn comm.CommandType = CommandType.Text comm.CommandText = selectformstr Adapter.SelectCommand = comm CB = New OleDb.OleDbCommandBuilder(Adapter) CB.QuotePrefix = "[" CB.QuoteSuffix = "]" If CB Is Nothing Then CB.DataAdapter = New OleDb.OleDbDataAdapter Adapter.DeleteCommand = CB.DataAdapter.DeleteCommand Adapter.InsertCommand = CB.DataAdapter.InsertCommand Adapter.UpdateCommand = CB.DataAdapter.UpdateCommand End If Dim temptb As DataTable Dim DR As DialogResult temptb = pubtable.GetChanges() If temptb IsNot Nothing Then DR = MsgBox("數(shù)據(jù)已改變,是否要保存?", MsgBoxStyle.YesNo, "提示" ![]() If DR = Windows.Forms.DialogResult.Yes Then Adapter.Update(pubtable) MsgBox("更新成功", MsgBoxStyle.DefaultButton1, "提示" ![]() Else : Exit Sub End If Else : Exit Sub End If conn.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click updataTable("provider=Microsoft.jet.oledb.4.0;Data source= AAA.mdb", AAADataSet1.Tables("huaxue" , "應填什么SQL語句"![]() End Sub 我是一個菜鳥 紅字部分應該填什么。恐x謝! |

木蟲 (著名寫手)
龍

| 8 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 274求調劑 +3 | S.H1 2026-03-18 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 一志愿武理材料305分求調劑 +5 | 想上岸的鯉魚 2026-03-18 | 6/300 |
|
|
[考研] 材料專碩英一數(shù)二306 +3 | z1z2z3879 2026-03-18 | 3/150 |
|
|
[考研] 354求調劑 +3 | Tyoumou 2026-03-18 | 5/250 |
|
|
[考研] 344求調劑 +5 | knight344 2026-03-16 | 6/300 |
|
|
[考研] 311求調劑 +6 | 26研0 2026-03-15 | 6/300 |
|
|
[考研] 298-一志愿中國農業(yè)大學-求調劑 +7 | 手機用戶 2026-03-17 | 7/350 |
|
|
[考研] 280求調劑 +6 | 咕嚕曉曉 2026-03-18 | 7/350 |
|
|
[考研] 296求調劑 +5 | 大口吃飯 身體健 2026-03-13 | 5/250 |
|
|
[考研] 301求調劑 +4 | A_JiXing 2026-03-16 | 4/200 |
|
|
[考研] 材料工程專碩調劑 +5 | 204818@lcx 2026-03-17 | 5/250 |
|
|
[考研] 326求調劑 +5 | 上岸的小葡 2026-03-15 | 6/300 |
|
|
[考研] 085601求調劑 +4 | Du.11 2026-03-16 | 4/200 |
|
|
[考研] 085600調劑 +5 | 漾漾123sun 2026-03-12 | 6/300 |
|
|
[考研] 一志愿哈工大材料324分求調劑 +5 | 閆旭東 2026-03-14 | 5/250 |
|
|
[考研] 304求調劑 +6 | Mochaaaa 2026-03-12 | 7/350 |
|
|
[碩博家園] 085600 260分求調劑 +3 | 天空還下雨么 2026-03-13 | 5/250 |
|
|
[考研] 085600材料與化工 309分請求調劑 +7 | dtdxzxx 2026-03-12 | 8/400 |
|
|
[考研] 材料301分求調劑 +5 | Liyouyumairs 2026-03-12 | 5/250 |
|
|
[考研] 333求調劑 +3 | 152697 2026-03-12 | 4/200 |
|