Dim sqlCommand As String = "select * from [Drug_Info] Where (Drug_Name = ?) and (Price between ? and ?) and(Producer = ?) and (Adaptation = ?)"
        SqlDataSource1.SelectParameters.Add(New Parameter("drug_Name", TypeCode.String, Nothing))
        SqlDataSource1.SelectParameters.Add(New Parameter("price1", TypeCode.Double, Nothing))
        SqlDataSource1.SelectParameters.Add(New Parameter("price2", TypeCode.Double, Nothing))
        SqlDataSource1.SelectParameters.Add(New Parameter("producer", TypeCode.String, Nothing))
        SqlDataSource1.SelectParameters.Add(New Parameter("adapt", TypeCode.String, Nothing))        SqlDataSource1.SelectParameters.Add("Drug_Name", TextBox1.Text.Trim())
        SqlDataSource1.SelectParameters.Add("price1", TextBox2.Text.Trim())
        SqlDataSource1.SelectParameters.Add("price2", TextBox3.Text.Trim())
        SqlDataSource1.SelectParameters.Add("producer", TextBox4.Text.Trim())
        SqlDataSource1.SelectParameters.Add("adapt", TextBox5.Text.Trim())        SqlDataSource1.Select(New DataSourceSelectArguments())
我的SqlDataSource是和GridView一起搭配使用的,想实现的功能是有根据4个文本框里的值进行查询(最好是模糊查询),有一个查询按钮Button1,我想点击它实现查询。但是像我上面这样做却实现不了。而且SqlDataSource的其他三个方法Insert、Update、Delete都没有参数。唯独Select里要有一个参数,这个参数我真不知道怎么写。
麻烦大家帮我看看,分不是问题.

解决方案 »

  1.   


    --更改查询语句的写法即可,如:
    select * from [Drug_Info] Where (Drug_Name like ?) and (Price between ? and ?) and(Producer like ?) and (Adaptation like ?)
      

  2.   

            Dim sql As String = "select * from [Drug_Info] Where 1 = 1"        If Not String.IsNullOrEmpty(TextBox1.Text.Trim()) Then
                sql = sql & " Drug_Name = " & TextBox1.Text.Trim()
            End If
            If Not String.IsNullOrEmpty(TextBox2.Text.Trim()) Then
                sql = sql & " Price > " & TextBox1.Text.Trim()
            End If
            If Not String.IsNullOrEmpty(TextBox3.Text.Trim()) Then
                sql = sql & " Price < " & TextBox3.Text.Trim()
            End If
            If Not String.IsNullOrEmpty(TextBox4.Text.Trim()) Then
                sql = sql & " Producer = " & TextBox4.Text.Trim()
            End If
            If Not String.IsNullOrEmpty(TextBox5.Text.Trim()) Then
                sql = sql & " Adaptation = " & TextBox5.Text.Trim()
            End If        'Response.Write(sql)        SqlDataSource1.SelectCommand = sql
            SqlDataSource1.Select(New DataSourceSelectArguments())
            GridView1.DataSourceID = SqlDataSource1.ID
      

  3.   

            SqlDataSource1.SelectParameters.Add(New Parameter("drug_Name", TypeCode.String, Nothing))
            SqlDataSource1.SelectParameters.Add(New Parameter("price1", TypeCode.Double, Nothing))
            SqlDataSource1.SelectParameters.Add(New Parameter("price2", TypeCode.Double, Nothing))
            SqlDataSource1.SelectParameters.Add(New Parameter("producer", TypeCode.String, Nothing))
            SqlDataSource1.SelectParameters.Add(New Parameter("adapt", TypeCode.String, Nothing))
    这些去掉看看。
      

  4.   

    我的方法以前这样用过,如果不可以,楼主请帖出错信息还有一种方法,就是在存储过程里动态拼接SQL语句处理
      

  5.   

    直到今天我还不会用这个SqlDataSource=
      

  6.   

    LZ你越界啦 你也不按套路出牌呀  这里是asp.net版哦
    不会asp