dr.read()读取不到记录问题??
我测试sql语句在查询分析器中能查出记录,但是为什么dr.read()不执行?代码如下:str_xm = Session("xm")--------------------编程问答-------------------- 程序逐句调试时,执行到Do While dr_lct.Read() 直接跳出了
strsql_lct = "select * from tabjh where jhlct like ""*" & str_xm & "*"""
'strsql_lct = "select * from tabjh where jhlct like ""/" & str_xm & "/"""
Dim cmd_lct As New OleDbCommand(strsql_lct, conn)
conn.Open()
Dim dr_lct As OleDbDataReader = cmd_lct.ExecuteReader()
lab_tab.Text = "<table width='90%' border='1'><tr bgcolor='#CDCDCD'><td>计划名称</td><td>起草人</td></tr>"
Do While dr_lct.Read()
str_jhlct = dr_lct.Item("jhlct")
int_jhzt = dr_lct.Item("jhzt")
str_jhbh = dr_lct.Item("jhbh")
shuzu_lct = Split(str_jhlct, "/")
int_xm_wz = Array.IndexOf(shuzu_lct, str_xm)
int_cha = int_xm_wz - int_jhzt
If int_cha = 1 Then
'strsql = "select * from tabjh where jhlct like ""%" & str_xm & "%"" and jhbh='" & str_jhbh & "'"
'strsql = "select * from tabjh where jhlct like ""%" & str_xm & "%"" and int_cha=1"
'strsql = "select * from tabjh where jhlct like ""%" & str_xm & "%"""
'strsql = "select * from tabjh where jhzt-(len(left(jhlct,CHARINDEX('" & str_xm & "',jhlct,0)+1))-len(replace(left(jhlct,CHARINDEX('" & str_xm & "',jhlct,0)+1),'/','')))=1"
'strsql = "select * from tabjh where (dr_lct.item('jhzt')-Array.IndexOf(Split(dr_lct.Item('jhlct'), " / "), '" & str_xm & "'))=1"
'strsql = "select * from tabjh where" & dr_lct.Item("jhzt") = 1
'Dim cmd As New OleDbCommand(strsql, conn)
'Dim dr As OleDbDataReader = cmd.ExecuteReader()
'dg_jhdb.DataSource = dr
'dg_jhdb.DataBind()
lab_tab.Text &= "<tr>"
lab_tab.Text &= "<td>" & dr_lct.Item("jhmc") & "</td>"
lab_tab.Text &= "<td>" & dr_lct.Item("jhqcr") & "</td>"
lab_tab.Text &= "</tr>"
End If
Loop
lab_tab.Text &= "</table>"
conn.Close()
--------------------编程问答-------------------- like 两边应该是单引号吧
strsql_lct = "select * from tabjh where jhlct like '*" & str_xm & "*'" --------------------编程问答-------------------- 你这是什么数据库,通配符是*吗?换成%试试 --------------------编程问答-------------------- 没有记录 SQL语句问题
试试"select * from tabjh where jhlct like ""%" & str_xm & "%""" --------------------编程问答-------------------- 用了like 就用%和单引号试试 肯定是sql语句写错了,在查询器里查得到在程序里面不一定能查到。语句不一样的!特别是""和'' --------------------编程问答--------------------
你的语句应该有问题:如果是这样select * from tabjh where jhlct like '*'查询出来是没数据的
如果你要用模糊查询的话应该这样的select * from tabjh where jhlct like '你要中的关键字%'
补充:.NET技术 , ASP.NET