标题:登录功能无法实现
只看楼主
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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-102091-1-1.html




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

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