[.NET] 如何使用listbox,直接將選取的listbox值存入資料庫
我做一個簡易的前端介面
簡易說明問題
有1個listbox跟一個button
listbox存放自己打好的字串
listbox的屬性設定裡的databindings中的selectitem連結了我要將選擇字串存入的資料
表
選好listbox的字串後
按下button就會將選擇的字串存入資料庫
我直接拖曳bindsource到介面中
問題出現了
當我按下button後
資料庫並沒有任何更新
而且出現例外處理
(invalidoperationexception :你需要一個更有利的updatacommand)
button的程式碼如下
請輸入程式碼
2 Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
3
4 Try
5 關鍵BindingSource.AddNew()
6 Catch ex As Exception
7
8 End Try
9 Try
10 關鍵BindingSource.EndEdit()
11 關鍵TableAdapter.Update(關鍵字DataSet)
12
13 Catch ex As Exception
14
15 End Try
16
17 End Sub
想請以上問題如何解決
已經卡了好幾天
或是有效的資料庫寫入方法
請指教一下
感激不盡
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.160.237.35
推
09/19 00:56, , 1F
09/19 00:56, 1F