贴码,一个简单的查询问题
'获取搜索关键字
Dim key As String = Me.txtKey.Text.Trim()
'关键字不空时执行搜索
If key <> " " Then
'新建连接
Dim conn As New SqlConnection
conn.ConnectionString = ConfigurationSettings.AppSettings( "ConnectionString ")
'新建命令
Dim cmd As New SqlCommand
cmd.CommandText = "Select material_id,material_name,material_specification,weight,in_time,kind,purchaser,carno,bz from material "
'按姓名搜索
cmd.CommandText += "where material_id like '% " + key + "% ' "
'按地址搜索
cmd.CommandText += "or purchaser like '% " + key + "% ' "
'按电话搜索
cmd.CommandText += "or material_specification like '% " + key + "% ' "
'按邮箱搜索
cmd.CommandText += "or bz like '% " + key + "% ' "
cmd.Connection = conn
'打开连接,执行操作,返回阅读器
conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
'绑定数据
Me.myGrid.DataSource = reader
Me.myGrid.DataBind()
&n