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里要有一个参数,这个参数我真不知道怎么写。
麻烦大家帮我看看,分不是问题.
解决方案 »
- 一个穷举算法【看看.NET程序员的算法水准】
- 上传文件问题
- 用WebDeployment 发布时出现这样的错误 1 未将对象引用设置到对象的实例。 ASPNETCOMPILER 1 1 是否有人知道
- 请问Web中DataGrid的宽度能够像桌面开发中的DataGird那样,通过鼠标可以拉动生成表格的宽度,可以灵活控制表格列宽度吗?
- 提个问先:GridView嵌套在TableCell中的居中问题
- 用NET做WAP开发时,如何在FORM之间传递参数啊,以及关于类似DataBinder.Eval(Container.DataItem,"PKID")在LIST中的使用
- 在不改写存储过程的情况下,如何返回记录总数?
- datagrid导数据到EXCEL出现的问题求解
- 还有这么个问题,大家帮忙看看!!我就不明白了,怎么这么多问题!!
- datagrid问题
- gridview 换页时 datakeys count =0 rows=10 这是怎么加事?
- 如何使用datagrid实现统计功能?
--更改查询语句的写法即可,如:
select * from [Drug_Info] Where (Drug_Name like ?) and (Price between ? and ?) and(Producer like ?) and (Adaptation like ?)
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
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))
这些去掉看看。
不会asp