| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 508 人关注过本帖
标题:登录功能无法实现
只看楼主 加入收藏
yuiolivia
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2005-12-5
收藏
 问题点数:0 回复次数:6 
登录功能无法实现

Dim conn As New SqlConnection("server=.;database=login;integrated security=sspi")
Dim comm As New SqlCommand
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Dim user, password As String
user = ComboBox1.Text
password = TextBox1.Text
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
comm.Connection = conn
comm.CommandType = CommandType.Text
comm.CommandText = "select * from Login where username = '" & user & "' and password = '" & password & "'"
da.SelectCommand = comm
If comm.CommandType <> 0 Then
MessageBox.Show("GO!")
Else
MessageBox.Show("NO!")
ComboBox1.Text = ""
TextBox1.Text = ""
ComboBox1.Focus()
Me.Focus()
End If
conn.Close()
这是button里的代码,为什么无论密码对错都是“GO”啊?
大家指点一下!谢谢~

搜索更多相关主题的帖子: 登录 
2006-11-10 20:33
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
你的comm.CommandText 始终者是 "select * from Login where username = '" & user & "' and password = '" & password & "'"

If comm.CommandType <> 0 Then
这句当然是正确的啦.

飘过~~
2006-11-10 20:49
yuiolivia
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2005-12-5
收藏
得分:0 
那应该怎么改啊?
2006-11-10 20:57
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
[CODE] da.SelectCommand = comm
If comm.ExecuteNonQuery() > 0 Then
MessageBox.Show("GO!")
Else
MessageBox.Show("NO!")
ComboBox1.Text = ""
TextBox1.Text = ""
ComboBox1.Focus()
Me.Focus()
End If
conn.Close()[/CODE]

飘过~~
2006-11-11 15:24
yuiolivia
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2005-12-5
收藏
得分:0 
comm.Connection = conn
comm.CommandType = CommandType.Text
comm.CommandText = "select * from Login where username = '" & user & "' and password = '" & password & "'"
da.SelectCommand = comm
'da.Fill(ds)
If comm.ExecuteNonQuery > 0 Then
MessageBox.Show("GO!")
Else
MessageBox.Show("NO!")
ComboBox1.Text = ""
TextBox1.Text = ""
ComboBox1.Focus()
Me.Focus()
End If
conn.Close()

改了以后就只显示NO了无论输什么密码~
2006-11-12 09:11
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
user = ComboBox1.Text.Trim()
password = TextBox1.Text.Trim()
加上这个试试.

飘过~~
2006-11-12 14:55
yuiolivia
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2005-12-5
收藏
得分:0 
还是不行!这是全部代码:
Dim user, password As String
user = ComboBox1.Text.Trim
password = TextBox1.Text.Trim
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
comm.Connection = conn
comm.CommandType = CommandType.Text
comm.CommandText = "select * from Login where username = '" & user & "' and password = '" & password & "'"
da.SelectCommand = comm
da.Fill(ds)
If comm.ExecuteNonQuery > 0 Then
MessageBox.Show("GO!")
Else
MessageBox.Show("NO!")
ComboBox1.Text = ""
TextBox1.Text = ""
ComboBox1.Focus()
Me.Focus()
End If
conn.Close()
2006-11-12 21:24
快速回复:登录功能无法实现
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016265 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved