1、使用传递字符串:
Dim sql As String
sql = "select xingming=count(*) from login where gys_name='" & tb_kehu.Text & "'and gys_password='" & tb_mima.Text & "'"
SqlConnection1.Open()
SqlCommand1.CommandText = sql
Dim reader As SqlClient.SqlDataReader
reader = SqlCommand1.ExecuteReader
If reader.Read Then
If reader("xingming") > 0 Then
Me.Response.Redirect("result.aspx?name=" & System.Web.HttpUtility.HtmlEncode(tb_kehu.Text) & " & password=" & System.Web.HttpUtility.HtmlEncode(tb_mima.Text))
Else
Label4.Text = "你输入的用户名或密码错误,请核实后输入!"
End If
End If
reader.Close()
SqlConnection1.Close()
2、接受查询字符串变量
Sub datagrid()
Dim MyCommand As SqlDataAdapter
Dim MyConnection As SqlConnection
Dim SelectCommand As String = "select * from user_login where gys_id = @gys_id order by id "
MyConnection = New SqlConnection("workstation id=WEIZHI;packet size=4096;integrated security=SSPI;initial catalog=p" & _
"rovide;persist security info=False")
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)
MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@gys_id", SqlDbType.NVarChar, 50))
MyCommand.SelectCommand.Parameters("@gys_id").Value = Request.Params("name")
Dim DS As New DataSet
MyCommand.Fill(DS, "user_login")
myDataGrid.DataSource = DS.Tables("user_login").DefaultView
myDataGrid.DataBind()
With ddl
.DataSource = DS.Tables("user_login").DefaultView
.DataSource = DS
.DataTextField = "spbh"
.DataBind()
End With