我在一个页面获取要修改信息的ID,然后判断数据库中有无此记录,若有此记录,则转向另一个页面,若无此记录,则弹出“无此记录”的信息框,在另一个页面的一个Textbox1。text获取上个页面传过来的值,但在运行时,老是出现“无此记录”,而且还转向另一个页面。(我的数据库里有那个记录)
数据库字段:ad_id,ad_password,ad_name
对应的类型:char .char ,varchar
代码如下:
Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("aa"))
Dim cmd As New SqlCommand
Dim dr As New SqlDataAdapter
Dim ds As New DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim cook As HttpCookie = New HttpCookie("yh")
cook.Values("id") = TextBox1.Text
Response.Cookies.Add(cook)
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select * from ad where ad_id='" & TextBox1.Text & "'"
dr.SelectCommand = cmd
dr.Fill(ds, "ad")
Dim tab As New DataTable
tab = ds.Tables("ad")
If ds.Tables("ad").Rows.Count = 0 Then
Response.Write("<script language='javascript'>alert ('无此用户!!');</script>")
Else
Response.Redirect("azhanghu.aspx")
End If
If conn.State = ConnectionState.Open Then
conn.Close()
End If