62,046
社区成员
发帖
与我相关
我的任务
分享
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())
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
--更改查询语句的写法即可,如:
select * from [Drug_Info] Where (Drug_Name like ?) and (Price between ? and ?) and(Producer like ?) and (Adaptation like ?)