当我在excel文件中添加新数据时,我想自动递增ID。这段代码中有什么错误,错误显示为“查询表达式'MAX [ID]'中的语法错误(缺少运算符)'”
Dim Value As Integer
cn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "C:\\Users\\Barbatos\\Desktop\\Book3.xlsx " + ";Extended Properties=Excel 12.0;")
cm = New OleDbCommand("SELECT MAX [ID] FROM [Sheet1$]", cn)'error here
cn.Open()
Dim dr As OleDbDataReader = cm.ExecuteReader()
If dr.HasRows Then
dr.Read()
Value = dr(0)
Else
End If
dr.Close()
答案 0 :(得分:-1)
MAX
是一个函数,因此您需要在括号中添加参数:
SELECT MAX([ID]) FROM [Sheet1$]