從vb程序插入查詢不會在訪問數據庫中添加記錄。SQL插入沒有結果
database connection class-->
Imports System.Data.OleDb
Public Class Data
Shared dbconnection As OleDbConnection
Shared dbcommand As OleDbCommand
Shared dbadapter As OleDbDataAdapter
Shared connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\DELL\Documents\Visual Studio 2013\Projects\Chakana saving and credit\Chakana saving and credit\Chakana.mdb"
Shared dbtable As DataTable
Public Shared Function loadData(query As String, Optional ReturnValue As Boolean = False)
dbconnection = New OleDbConnection(connectionString)
dbadapter = New OleDbDataAdapter
dbtable = New DataTable()
dbcommand = New OleDbCommand(query)
dbcommand.CommandType = CommandType.TableDirect
dbadapter.SelectCommand = dbcommand
dbadapter.SelectCommand.Connection = dbconnection
dbconnection.Open()
'MsgBox("query lexecute")
If ReturnValue = True Then
dbadapter.Fill(dbtable)
Return dbtable
Else
Return 0
End If
End Function
末級
函數調用傳遞參數查詢
query = "INSERT INTO CustomerInfo (ClientId,FirstName) VALUES ('23','abce')"
Data.loadData(query)
其他調用函數傳遞一個SELECT查詢工作正常,但是當我嘗試插入查詢和事後從訪問它打開數據庫沒有結果
您還沒有執行過 – Steve
那麼爲什麼選擇查詢(其它形式)執行正確調用這個非常相同的功能,當查詢? query =「SELECT Password,AccountType FROM Cooperative WHERE UserName =」+「'」+用戶名+「'」 tdata = Data.loadData(query,True) –
您將更新查詢設置爲select命令。 –