不知道我在这里做错了什么,在“InTime”附近不断出现语法错误。sqlmodDA.Update(sqlmodDS.Tables("XXX")) 一个按钮获取数据 (subBindDataGridView) 以显示在数据网格视图上,然后进行编辑下一个按钮 (CommitChanges) 将更改写入 DB。由于加入 Select 命令,无法使用命令生成器。我最好只使用所有存储过程解决方案吗?
Imports System.Data
Imports System.Data.SqlClient
Module SQLSever
Private sqlmodCon As SqlConnection
Private sqlmodDA As SqlDataAdapter
Private sqlmodTA As New DataTable
Private sqlmodDS As New DataSet
Sub subBindDataGridView()
Dim strConStr As String
Dim SQLState As String
Dim SQLUpdate As String
strConStr = "Server=sql2008;Database=TimeClock;User ID=VBA;Password=CanIJustUseDA0;"
sqlmodCon = New SqlConnection(strConStr)
sqlmodCon.Open()
SQLState = "SELECT * FROM dbo.tblEvents INNER JOIN dbo.tblPersons ON dbo.tblEvents.PersonID = dbo.tblPersons.PersonID;"
SQLUpdate = "UPDATE dbo.tblEvents" & _
"SET InTime = @InTime, LunchStart = @LunchStart, LunchFinish = @LunchFinish, OutTime = @OutTime WHERE Pkey = @Pkey;"
sqlmodDA = New SqlDataAdapter(SQLState, sqlmodCon)
sqlmodDA.UpdateCommand = New SqlCommand(SQLUpdate, sqlmodCon)
sqlmodDA.UpdateCommand.Parameters.Add("@InTime", SqlDbType.DateTime, 8, "InTime")
sqlmodDA.UpdateCommand.Parameters.Add("@LunchStart", SqlDbType.DateTime, 8, "LunchStart").SourceColumn = "LunchStart"
sqlmodDA.UpdateCommand.Parameters.Add("@LunchFinish", SqlDbType.DateTime, 8, "LunchFinish").SourceColumn = "LunchFinish"
sqlmodDA.UpdateCommand.Parameters.Add("@OutTime", SqlDbType.DateTime, 8, "OutTime").SourceColumn = "OutTime"
sqlmodDA.UpdateCommand.Parameters.Add("@PKey", SqlDbType.BigInt, 8, "Pkey").SourceColumn = "PKey"
sqlmodDA.Fill(sqlmodDS, "XXX")
Form1.DataBox.DataSource = sqlmodDS.Tables("XXX")
sqlmodCon.Close()
End Sub
Sub CommitChanges()
sqlmodCon.Open()
sqlmodDA.Update(sqlmodDS.Tables("XXX")) 'Error here
sqlmodDS.AcceptChanges()
sqlmodCon.Close()
End Sub
端模块