'查询产品信息 Public Function GetProduct_Info(ByVal Name As String) As DataTable conn.Open() Access = "Select ID, ClassName, Name, AddTime, IsShow FROM Product_Info where Name like '%'+@Name+'%'" Adcmd = New OleDbDataAdapter(Access, conn) Adcmd.SelectCommand.Parameters.Add("@Name", OleDbType.Char).Value = Name Dim dt As New DataTable Try Adcmd.Fill(dt) Catch ex As Exception Finally conn.Close() End Try Return dt End Function
GridView是SQL语句自己写好的。现在我要点按钮使得GridView里面的SQL语句和传过来的值匹配,应该怎样操作?
看這里
Public Function GetProduct_Info(ByVal Name As String) As DataTable
conn.Open()
Access = "Select ID, ClassName, Name, AddTime, IsShow FROM Product_Info where Name like '%'+@Name+'%'"
Adcmd = New OleDbDataAdapter(Access, conn)
Adcmd.SelectCommand.Parameters.Add("@Name", OleDbType.Char).Value = Name
Dim dt As New DataTable
Try
Adcmd.Fill(dt)
Catch ex As Exception
Finally
conn.Close()
End Try
Return dt
End Function
Public String strSQL ;
string Str = Session["name"].ToString();
strSQL ="select * from table_name where [code]='"+Str+"'";
在GridView的SelectQurey中添加一个parameter,名字为code,类型为Session,SessionField为name。
示例SQL:SELECT * FROM table WHERE code = @code