我正在尝试使用以下代码获取date = today的Max字段:
Dim todaydate = Format(Today.Date, "dd/MM/yyyy")
Dim sql1 As String = "Select max(snum) From tblbill where idate = #" & todaydate & "# "
Dim conn1 As SqlConnection = New SqlConnection(constr)
Dim cmd1 As SqlCommand = New SqlCommand(sql1, conn1)
conn1.Open()
Dim dr1 As SqlDataReader = cmd1.ExecuteReader
dr1.Read()
If IsDBNull(dr1(0)) Then
TextBox6.Text = 1
Else
TextBox6.Text = dr1(0) + 1
End If
dr1.Close()
cmd1.Dispose()
conn1.Close()
Run Code Online (Sandbox Code Playgroud)
但是当运行app时我得到了这个错误: '#'附近的语法不正确. 请有人帮忙!
在我的结算表单中,我有一个按钮,可将datagridview数据插入两个访问数据库.我使用此代码插入第一个数据库:
Private Sub inserttotblbill()
Dim billcon As OleDbConnection = New OleDbConnection(constr)
Dim billcmd As New OleDbCommand
For i = 0 To dgv.Rows.Count - 1
billcon.Open()
billcmd.Connection = billcon
billcmd.CommandText = ("insert into tblbill(inum,snum,idate,cname,iname,iprc,iqnt,ipaid,itotal,iuser,itype) " _
& " values('" _
& TextBox1.Text _
& "','" _
& TextBox6.Text _
& "','" _
& TextBox2.Text _
& "','" _
& TextBox3.Text _
& "','" _
& dgv.Rows(i).Cells(0).Value _
& "','" _
& dgv.Rows(i).Cells(1).Value _
& "','" _
& dgv.Rows(i).Cells(2).Value _
& "','" …Run Code Online (Sandbox Code Playgroud)