我是菜鸟,提一个简单问题

Salif 2002-09-30 11:08:23
我的数据库是SQL Server,字段有id和end_date,请问在vb中如何判断数据库中的某个字段是否为空?
Dim m_lngId As Integer
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim rs As New ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String

txtSQL = "select * from Event where id=" & m_lngId & "'and isnull(end_date) " '"
rs.Open txtSQL, cnMain, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
MsgBox "请先按开始", vbOKOnly + vbExclamation, "警告"
rs.Close
Else
rs.Close
Unload Me
End If
End Sub
这句sql错在哪里,最好能给出完整的sql语句并帮我看看程序还有哪些错!
...全文
25 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Salif 2002-09-30
  • 打赏
  • 举报
回复
各位,end_date是字段名,它不是字符串形式,是不是要把end_date先赋给一个变量
arrow_gx 2002-09-30
  • 打赏
  • 举报
回复
我上面的SQL有点错,应该为

txtSQL = "select * from Event where id=" & m_lngId & "and end_data is null"
arrow_gx 2002-09-30
  • 打赏
  • 举报
回复
txtSQL = "select * from Event where id=" & m_lngId & "'and isnull(end_date) " '"
rs.Open txtSQL, cnMain, adOpenDynamic, adLockOptimistic

第二句话错了,Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
或第一句 Dim m_lngId As Integer 放到第二句

txtSQL = "select * from Event where id=" & m_lngId & "'and end_data is null " '"
houtianxi 2002-09-30
  • 打赏
  • 举报
回复
isnull()函数可以判断
道素 2002-09-30
  • 打赏
  • 举报
回复
txtSQL = "select * from Event where id=" & m_lngId & " and isnull(end_date) "
不要'号
mingqing 2002-09-30
  • 打赏
  • 举报
回复
此时应大厦大厦大厦确保cnmain已打开,否则也会出错!

如果m_lngld为整型的数字变量,应为
txtSQL = "select * from Event where id=" & m_lngId & " and isnull(end_date) "

为字符变量应为
txtSQL = "select * from Event where id='" & m_lngId & "' and isnull(end_date)"

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧