Dim olecn As New OleDb.OleDbConnection
Dim oleDA As New OleDb.OleDbDataAdapter
Dim olecomm As New OleDb.OleDbCommand
Dim oledS As New DataSet
Dim xxtable As New DataTable
Public Sub bindgridview()
olecn.ConnectionString = cnn ' 獲取聯接地址,"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\原F盤\vs2015-access引擎\技術流程系統資料庫.accdb"
olecomm.Connection = olecn '建立聯接
xxtable.Clear()
olecomm.CommandText = "select * from 登陸資訊 where 簡稱 = '" & UsernameTextBox.Text & "'" '執行查詢陳述句
oleDA.SelectCommand = olecomm '設配器獲取查詢命令
olecn.Open() '打開資料庫
oleDA.Fill(oledS, "登陸資訊") '對設配器填充資料
xxtable = oledS.Tables("登陸資訊")
' Dim myrow As DataRow = xxtable.NewRow
olecn.Close()
DataGridView1.DataSource = xxtable ' oledS.Tables("登陸資訊") 'oledS.Tables("登陸資訊") '將設配器上取到的資料表內容顯示到 顯示幕上
DataGridView1.Rows(0).DataBoundItem("密碼") = NewPasswordtextbox.Text
'oleDA.Update(oledS.Tables("登陸資訊"))
oleDA.Update(DataGridView1.DataSource)
' xxtable.Clear()
End Sub
datagridview資料能改過來,但只要重繪下,又是原來的資料,也就是說物理資料庫根本沒被修改,哪位大大指導下,到底是怎么回事!謝謝!急等!!
uj5u.com熱心網友回復:
沒有update成功,這個要定義commandbuilder吧,更新的是整個表,不是通過update陳述句。uj5u.com熱心網友回復:
bindgridview在什么時候呼叫的應該分開來,前半段綁表寫在 formload里面,后面更新寫在cell的change事件里
uj5u.com熱心網友回復:
新手,才學的VB.NET,今天重新看書,少了builder指令!
vb.net的書尤其是關于資料庫的書好少,給學習帶來不少麻煩!
uj5u.com熱心網友回復:
DataBind() 需要uj5u.com熱心網友回復:
推薦你用 command 的 ExecuteNonquery()uj5u.com熱心網友回復:
我已放棄用builder 來更新資料庫了,總會有莫名其妙的問題現在用UPDATE 帶欄位更新,尾巴一定要帶ID ,這樣就可以
If bl = "xg" Then
DataGridView1.CurrentRow.Cells.Item("經辦人").Value = qjxm
olecomm.CommandText = "update 引數及合同 set 作業介質='" & txt_jz.Text & "',相對濕度='" & txt_sd.Text _
& "',流量='" & txt_ll.Text & "',進氣壓力='" & txt_jqyl.Text & "',排氣壓力='" & txt_pqyl.Text & "',進氣溫度='" & txt_jqwd.Text _
& "',排氣溫度='" & txt_pqwd.Text & "',用戶='" & txt_yh.Text & "',合同號='" & txt_hth.Text & "',版本號='" & txt_bbh.Text _
& "',備注='" & txt_bz.Text & "',修改='" & qjxm & "',修改日期='" & Dtp_jbrq.Value & "'where id =" & datagw_jd
olecn.Open()
oleDA.SelectCommand = olecomm
olecomm.ExecuteNonQuery()
olecn.Close()
End If
uj5u.com熱心網友回復:
1) olecomm.CommandText = "select * from 引數及合同 where " & ComboBox1.Text & "= '" & txt_cx.Text & "'" '執行查詢陳述句2) olecomm.CommandText = "select * from 引數及合同 where " & ComboBox1.Text & "like '%" & txt_cx.Text & "%'" '執行查詢陳述句
現在有碰到問題了,執行1)可以查出資料來, 用2)句來查,什么都找不到,不指導為什么,請各位大神指導下.謝謝!
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/116309.html
標籤:VB.NET
上一篇:百度的Echarts城市地圖,怎么添加點擊城市區域事件?
下一篇:小白求解決
