<Script Language="VB" Runat="Server">
  Sub BindList(PageNo As Integer)
  Dim sorttwo As string
sorttwo = Request.QueryString("sorttwo")
    Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                               "Data Source=" & Server.MapPath("do#done.mdb")
if Request.QueryString("sorttwo") ="" then
     Dim strSQL As String = "Select * From table_pro where pro_vip = '"&cstr(0)&"' order by pro_id desc"
else
     Dim strSQL As String = "Select * From table_pro where pro_sort_two ='"& sorttwo &"' and pro_vip = '"&cstr(0)&"' order by pro_id desc"
end ifBy pro_id Desc"    Dim objCmd As New OleDbDataAdapter(strSQL, ConnString)
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
编译器错误信息: BC30451: 名称“strSQL”未声明。(上面最后一行)=================================================================
当我把:
if Request.QueryString("sorttwo") ="" then
     Dim strSQL As String = "Select * From table_pro where pro_vip = '"&cstr(0)&"' order by pro_id desc"
else
     Dim strSQL As String = "Select * From table_pro where pro_sort_two ='"& sorttwo &"' and pro_vip = '"&cstr(0)&"' order by pro_id desc"
end if
'************************
改成只要其中一句,如:
Dim strSQL As String = "Select * From table_pro where pro_vip = '"&cstr(0)&"' order by pro_id desc"
又不会出错,这是什么原因?
要怎么修改呢?

解决方案 »

  1.   

    Dim strSQL as stringif Request.QueryString("sorttwo") ="" then
         strSQL  = "Select * From table_pro where pro_vip = '"&cstr(0)&"' order by pro_id desc"
    else
         strSQL = "Select * From table_pro where pro_sort_two ='"& sorttwo &"' and pro_vip = '"&cstr(0)&"' order by pro_id desc"
    end if这样呢?
      

  2.   

    strSQL的作用域在if语句里面,出了if语句strSQL就"没了".
    楼主把strSQL定义在if语句上面就可以了.
      

  3.   

    把dim strsql as string 放到if else end if 语句之前了。在if语句里面对它进行赋值还有
    if Request.QueryString("sorttwo") ="" then//这个是赋值,不是比较吧?