以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]Select 条件表达式合成有误 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=187087) |
-- 作者:洮沙 -- 发布时间:2023/6/20 15:07:00 -- [求助]Select 条件表达式合成有误 老师,有以下代码,左右调试,始终错误,麻烦帮忙看一下,谢谢! dim fd as date dim ld as date dim zh as string cmd.C ommandText = "S elect max(凭证编号) From {凭证序时簿} Where 日期 >= #" & fd & "# And 日期 <= #" & ld & "# And 凭证编号 Like " & zh max = cmd.ExecuteScalar() .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2022.8.18.1 错误所在事件: 详细错误信息: 至少一个参数没有被指定值。 |
-- 作者:有点蓝 -- 发布时间:2023/6/20 15:12:00 -- 前面定义的3个变量没有赋值,这种代码没有任何存在意义,也肯定会出错 |
-- 作者:洮沙 -- 发布时间:2023/6/20 15:15:00 -- 老师是动态赋值的,完整代码如下: Dim e As RequestEventArgs = args(0) Dim dt As DataTable Dim cmd As New SQLCommand cmd.C cmd.CommandText = "S elect * From {凭证序时簿} Where [_Identify] Is null" \'生成空表 dt = cmd.ExecuteReader(True) Dim je As Decimal Dim sz As String Dim d As Date Dim zh As String Dim dr As DataRow If e.Values.Keys.ToString > "" Then dr = dt.AddNew() For Each key As String In e.Values.keys If key = "日期" Then dr("日期") = e.Values (key) d = e.Values (key) ElseIf key = "收支" Then sz = e.Values (key) ElseIf key = "金额" Then je = e.Values (key) ElseIf key = "科目" Then dr("会计科目_全名") = e.Values (key) ElseIf key = "字号" Then dr("凭证字") = e.Values (key) zh = e.Values (key) ElseIf key = "附件" Then dr("附件") = e.Values (key) ElseIf key = "制单" Then dr("制单") = e.Values (key) ElseIf key = "备注" Then dr("备注") = e.Values (key) End If Next End If If sz = "收入" Then dr("本期发生额_借方") = je Else dr("本期发生额_贷方") = je End If Dim n As Integer = zh.Length + 1 Dim y As Integer = d.Year Dim m As Integer = d.Month Dim Days As Integer = Date.DaysInMonth(y, m) Dim fd As Date = New Date(y, m, 1) \'获得该月的第一天 Dim ld As Date = New Date(y, m, Days) \'获得该月的最后一天 Dim max As String Dim sqlmax As String Dim idx As Integer cmd.CommandText = "S elect max(凭证编号) From {凭证序时簿} Where 日期 >= #" & fd & "# And 日期 <= #" & ld & "# And 凭证编号 Like " & zh max = cmd.ExecuteScalar() If max > "" Then \'如果存在最大编号 idx = CInt(max.Substring(n, 3)) Else idx = 0 End If idx = idx + 1 dr("凭证编号") = zh & "-" & Format(idx, "000") dr.Save() Dim s As String = "新增凭证成功,凭证编号:【" & dr("凭证编号") & "】。" e.WriteString(s) e.Handled = True 去掉 凭证编号 Like条件不报错 [此贴子已经被作者于2023/6/20 15:21:43编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/6/20 15:27:00 -- 说明条件有问题呀,弹出看看就应该知道了 cmd.CommandText = "S elect max(凭证编号) From {凭证序时簿} Where 日期 >= #" & fd & "# And 日期 <= #" & ld & "# And 凭证编号 Like " & zh msgbox( cmd.CommandText )
|
-- 作者:洮沙 -- 发布时间:2023/6/20 15:36:00 -- cmd.CommandText = "S elect max(凭证编号) From {凭证序时簿} Where 日期 >= #" & fd & "# And 日期 <= #" & ld & "# And 凭证编号 Like \'" & zh & "\'" 问题找到了,字符型变量单引号未添加造成的。
|