[.NET] 這是微軟的bug嗎?
請輸入專案類型(網站專案或者應用程式專案):
VB2005 + ACCESS 單機應用:
新增 刪除 更新時
gridview一直不能更新,爬文後發現應該是另外寫SQL進去的關係
於是我寫了一些東西下去更新:
以下是新增時的語法:
Private Sub btn_insert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_insert.Click
If txt_cusname.Text = "" Then
MsgBox("請輸入客戶姓名!")
Else
Dim connDbStr, selectCmd As String '定義
connDbStr = "Provider=Microsoft.Jet.OLEDB.4.0;
DataSource=C:\Documents and Settings\User\My Documents\Visual Studio
2005\Projects\0828\SD\0829.mdb;" '引入資料庫
'以下新增語法:
selectCmd = "INSERT INTO cus_bdata
(cus_name,occu,cell_phone,home_phone,fax,E_mail,addr,birth,remark) VALUES ('"
& (txt_cusname.Text) & "', '" & (txt_job.Text) & "','" & (txt_cellphone.Text)
& "','" & (txt_home.Text) & "','" & (txt_fax.Text) & "', '" &
(txt_email.Text) & "', '" & (txt_addr.Text) & "',#" & (mtxt_cusbir.Text) &
"#,'" & (txt_cusmeno.Text) & "')"
Dim conn As OleDbConnection = New OleDbConnection(connDbStr)
conn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(selectCmd, conn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter(selectCmd,conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "cus_bdata")
DataGridView1.DataSource = ds.Tables("cus_bdata").AddNew()
cmd.ExecuteNonQuery()
conn.Close()
da.Dispose()
MsgBox("SUCCESS")
txt_cusid.Text = ""
txt_cusname.Text = ""
txt_job.Text = ""
txt_cellphone.Text = ""
txt_home.Text = ""
txt_fax.Text = ""
txt_email.Text = ""
txt_addr.Text = ""
mtxt_cusbir.Text = ""
txt_cusmeno.Text = ""
End If
End Sub
雖然可以成功更新,但gridview裡的資料會全部不見= =....
有高手知道這是怎麼一回事咩? = =
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.179.102
※ 編輯: saieva 來自: 122.116.179.102 (09/04 22:00)
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):