编程论坛's Archiver

HR岩 发表于 2007-11-5 20:51

[求助]查询按钮代码错误

<P>在查询按钮下:<BR>        strsql = "SELECT patID ,"<BR>        strsql &amp;= "patnam, "<BR>        strsql &amp;= "patnamkan,"<BR>        strsql &amp;= "patbirdat,"<BR>        strsql &amp;= "patsex, "<BR>        strsql &amp;= "numpatrelstu "<BR>        strsql &amp;= "From PatientLevel "<BR>        <BR>        <FONT color=#ee1111>If txtPatName.Text &lt;&gt; "" Then<BR>            strsql &amp;= "and patnam like '" &amp; txtPatName.Text &amp; "' "<BR>        ElseIf txtPatID.Text &lt;&gt; "" Then<BR>            strsql &amp;= "and patID like '" &amp; txtPatID.Text &amp; "%' "<BR>        ElseIf cboPatSex.Text &lt;&gt; "" Then<BR>            strsql &amp;= "and patsex = '" &amp; cboPatSex.Text &amp; "' "<BR>        End If<BR></FONT>        Try<BR>            dt.Clear()<BR>            cn.Open()<BR>            da = New SqlDataAdapter(strsql, cn)<BR>            da.Fill(dt)<BR>            grdPatList.DataSource = dt<BR>            btnModify.Enabled = True<BR>            btnDel.Enabled = True<BR>            If dt.Rows.Count = 0 Then</P>
<P>                MsgBox("该查询结果不存在。")</P>
<P>            End If</P>
<P>            da.Dispose()<BR>        Catch ex As Exception<BR>            MsgBox(ex.Message)</P>
<P>        Finally<BR>            If cn.State = ConnectionState.Open Then<BR>                cn.Close()</P>
<P>            End If<BR>        End Try</P>

purana 发表于 2007-11-5 20:54

你有什么问题你说出来啊..<BR>不要发段代码出来..什么事也不管了..

fairy4 发表于 2007-11-6 08:47

<P>你知道這段代碼執行后,STRSQL是什么不?<BR>、  strsql = "SELECT patID ,"<BR>        strsql &amp;= "patnam, "<BR>        strsql &amp;= "patnamkan,"<BR>        strsql &amp;= "patbirdat,"<BR>        strsql &amp;= "patsex, "<BR>        strsql &amp;= "numpatrelstu "<BR>        strsql &amp;= "From PatientLevel "<BR>        <BR>        If txtPatName.Text &lt;&gt; "" Then<BR>            strsql &amp;= "and patnam like '" &amp; txtPatName.Text &amp; "' "<BR>        ElseIf txtPatID.Text &lt;&gt; "" Then<BR>            strsql &amp;= "and patID like '" &amp; txtPatID.Text &amp; "%' "<BR>        ElseIf cboPatSex.Text &lt;&gt; "" Then<BR>            strsql &amp;= "and patsex = '" &amp; cboPatSex.Text &amp; "' "<BR>        End If<BR>寫出這樣的代碼,服了你!<BR>你用msgbox(strsql)輸出下!</P>

HR岩 发表于 2007-11-18 19:35

不好意思~~忘了写上定义STRSQL~~我是在全局变量里定义的~<BR><BR><BR>

bygg 发表于 2007-11-19 11:03

strsql &amp;= "From PatientLevel "<br><FONT color=#ff0000>=======&gt;<br></FONT>strsql &amp;= "From PatientLevel where 1=1 "<br>
[align=right][color=#000066][此贴子已经被作者于2007-11-19 11:04:15编辑过][/color][/align]


页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.