数据库操作时出现日期类型不匹配help me!

chinayeren 2008-04-02 03:22:00
If tf = True Or rbut_all.Checked = True Then
Dim cmd As String
cmd = "select [id],[class],[smallclass],[type],[add],[username],[condition],[bm],[data],[bz] from zcinfo"
If rbut_all.Checked = True Then
'==============打开selectview窗口并且传递sqlcmd
selectview.sqlcmd = cmd
Else
If chb_bm.Checked = False And chb_class.Checked = False And chb_data.Checked = False _
And chb_name.Checked = False And chb_smallclass.Checked = False And chb_xh.Checked = False _
And chb_zt.Checked = False Then
'selectview.sqlcmd = cmd
Else
cmd = "select [id],[class],[smallclass],[type],[add],[username],[condition],[bm],[data],[bz] from zcinfo where "
End If

'==============组合sql语句为给sqlcmd传递服务
'==检测大类是否被选中
Dim pdtf As Boolean
pdtf = False
If chb_class.Checked = True Then
pdtf = True
cmd += "class=" + (cb_class.SelectedIndex + 1).ToString()
End If
'==检测存放地边是否被选中
If chb_sybm.Checked = True Then
If pdtf = False Then
cmd += "[add]='" + txt_sybm.Text + "'"
pdtf = True
Else
cmd += " and [add]='" + txt_sybm.Text + "'"
End If
End If
'==检测小类是否被选中
If chb_smallclass.Checked = True Then
If pdtf = False Then
cmd += "smallclass=" + (cb_smallclass.SelectedIndex + 1).ToString()
pdtf = True
Else
cmd += " and smallclass=" + (cb_smallclass.SelectedIndex + 1).ToString()
End If

End If
'==检测型号是否被选中
If chb_xh.Checked = True Then
If pdtf = False Then
cmd += "type='" + txt_xh.Text + "'"
pdtf = True
Else
cmd += " and type='" + txt_xh.Text + "'"
End If

End If
'==检测部门是否被选中
If chb_bm.Checked = True Then
If pdtf = False Then
cmd += "bm=" + (cb_bm.SelectedIndex + 1).ToString()
pdtf = True
Else
cmd += " and bm=" + (cb_bm.SelectedIndex + 1).ToString()
End If

End If
'==检测姓名是否被选中
If chb_name.Checked = True Then
If pdtf = False Then
cmd += "username='" + txt_name.Text + "'"
pdtf = True
Else
cmd += " and username='" + txt_name.Text + "'"
End If

End If
'==检测状态是否被选中
If chb_zt.Checked = True Then
If pdtf = False Then
'cmd += "[condition]=1"
cmd += "[condition]=" + cb_zt.SelectedIndex.ToString()
pdtf = True
Else
cmd += " and [condition]=" + cb_zt.SelectedIndex.ToString()
'cmd += " and [condition]=1"
End If

End If
'==检测日期是否被选中
If chb_data.Checked = True Then
If pdtf = False Then
cmd += "[data]>='" + dtp_1.Value.Date.ToString() + "' and [data]<='" + dtp_2.Value.Date.ToString() + "'"
pdtf = True
Else
cmd += " and [data]>='" + dtp_1.Value.Date.ToString() + _
"' and [data]<='" + dtp_2.Value.Date.ToString() + "'"
End If

End If
selectview.sqlcmd = cmd
End If
selectview.ShowDialog()
End If

后得到的cmd在selectview窗体内使用时抱错
Private Sub selectview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'测试窗口中传递信息是否成功
'MsgBox(sqlcmd, MsgBoxStyle.OkOnly, "提示")
'====将数据装入datagridview
Dim olecn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=固定资产.mdb")
Dim selectcmd As New OleDb.OleDbCommand()
selectcmd.Connection = olecn
Dim olead As New OleDb.OleDbDataAdapter()
olead.SelectCommand = selectcmd
olead.SelectCommand.CommandText = sqlcmd
Dim ds As New DataSet()
olead.Fill(ds)
dgv_select.DataSource = ds.Tables(0)
停在了olead.fill(ds)
...全文
142 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinayeren 2008-04-02
  • 打赏
  • 举报
回复
哈哈谢谢各位大侠了 终于结局了 果然是#号问题 好郁闷阿卡了好几个小时在整个问题上~~~~
langzi830428 2008-04-02
  • 打赏
  • 举报
回复
to 2楼
带时分秒不太影响吧。。
我做的一个程序从Oracle数据库中读入数据到DATAGRIDVIEW里,里面的DATATYPE是带十分秒的,但是我写入不带时分秒的数据进ORACLE数据库里,是没有问题的,似乎写进去的时候,ORACLE会自己帮你转成带时分秒的。
chinayeren 2008-04-02
  • 打赏
  • 举报
回复
请写个例子吧
langzi830428 2008-04-02
  • 打赏
  • 举报
回复
SQL的查找日期应是是 SELECT * FORM TABLE WHERE 'time' = TO_DATE(value , 'YYYY-MM-DD') 的格式
herol 2008-04-02
  • 打赏
  • 举报
回复
可能数据库里的日期类型和dtp里的日期类型不一样吧
可以一个带时分秒,一个不带时分秒
CloneCenter 2008-04-02
  • 打赏
  • 举报
回复
Access的日期貌似是用#来标识的!
建议使用OledbCommand + OledbParameter来实现,免去日期、数字等等这些数据格式的问题。

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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