以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  关于Select的问题(已解决)  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=10623)

--  作者:xiaoqiwei
--  发布时间:2011/6/15 12:14:00
--  关于Select的问题(已解决)

如果输入的账号不存在就弹窗提示“账号不存在”,请问代码应该怎么写啊?

请帮忙在我一下代码中添加,谢谢!

 

Dim UserName As String = e.Form.Controls("账号1").Value
Dim Usermima As String = e.Form.Controls("密码1").Value
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim dr As DataRow
cmd.C
If UserName = ""  Then
    Messagebox.show("请输入用户名!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
End If
cmd.CommandText = "Select * From {xtuser} Where [用户账号] = \'" & UserName & "\'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)
If Usermima = dr("用户密码") Then
    e.Form.Close
Else
    Messagebox.show("用户账号或密码不正确!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

 

[此贴子已经被作者于2011-6-15 17:56:24编辑过]

--  作者:blackzhu
--  发布时间:2011/6/15 12:30:00
--  
dt = cmd.ExecuteReader
If dt.count=0 then
Messagebox.show("账号不存在!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
end if

--  作者:xiaoqiwei
--  发布时间:2011/6/15 12:46:00
--  
以下是引用blackzhu在2011-6-15 12:30:00的发言:
dt = cmd.ExecuteReader
If dt.count=0 then
Messagebox.show("账号不存在!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
end if

输入该代码后,按确定就提示count 不是DataTable的成员


--  作者:xiaoqiwei
--  发布时间:2011/6/15 12:55:00
--  

帮忙看看以下代码出错在哪里!黄色字体的代码运行时提示“count 不是DataTable的成员”,粉红色字体的代码运行时提示“登录状态”不属于“表”,我是想账号密码正确就保存“登陆状态”为“TRUE”

 

Dim UserName As String = e.Form.Controls("账号1").Value
Dim Usermima As String = e.Form.Controls("密码1").Value
Dim rdo1 As WinForm.RadioButton
Dim rdo2 As WinForm.RadioButton
rdo1 = e.Form.Controls("收银台")
rdo2 = e.Form.Controls("管理台")
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim dr As DataRow
cmd.C
If UserName = ""  Then
    Messagebox.show("请输入用户名!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
ElseIf Usermima = ""  Then
    Messagebox.show("请输入登陆密码!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
ElseIf Usermima.Length <> 6 Then
    Messagebox.show("密码长度不足6位数!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
cmd.CommandText = "Select * From {xtuser} Where [用户账号] = \'" & UserName & "\'"
dt = cmd.ExecuteReader
If dt.count=0 Then
Messagebox.show("账号不存在!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
dr = dt.DataRows(0)
Dim dr1 As DataRow
If Usermima = dr("用户密码") Then
   If dr("登录状态") = False Then
      If rdo1.Checked = True Then
      dr1("登录状态") = True
      e.Form.Close()
      ElseIf rdo2.Checked = True Then
      MessageBox.Show("后台尚在制作中……暂时不能使用!", "温馨提示!")
      End If
   Else
   MessageBox.Show("该账号已经在其他终端登陆!", "温馨提示!")
   End If
Else
    Messagebox.show("用户账号或密码不正确!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If


--  作者:czy
--  发布时间:2011/6/15 12:58:00
--  

Dim cmd As New SQLCommand
cmd.CommandText = "Select Count(用户账号) From {xtuser} Where [用户账号] = \'" & UserName & "\'"
If cmd.ExecuteScalar() = 0 Then
    Messagebox.show("账号不存在!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

另外我觉得用UserName似乎不妥,应该用User.Name,我猜的。


--  作者:xiaoqiwei
--  发布时间:2011/6/15 13:10:00
--  
以下是引用czy在2011-6-15 12:58:00的发言:

Dim cmd As New SQLCommand
cmd.CommandText = "Select Count(用户账号) From {xtuser} Where [用户账号] = \'" & UserName & "\'"
If cmd.ExecuteScalar() = 0 Then
    Messagebox.show("账号不存在!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

另外我觉得用UserName似乎不妥,应该用User.Name,我猜的。

账号不存在提示问题已经解决,谢谢!

第二个问题:粉红色字体的代码运行时提示“登录状态”不属于“表”,我是想账号密码正确就保存“登陆状态”为“TRUE”

 

请问如何将TRUE保存到“登录状态”列中呢?


--  作者:blackzhu
--  发布时间:2011/6/15 13:14:00
--  
Dim S As String = e.Form.Controls("TextBox1").Value
Dim cmd As New SQLCommand
Dim dt As datatable
cmd.C  \'外部数据源名称
cmd.CommandText = "SELECT * From {送货地址} Where [客户] = \'"& S &"\'" 
dt = cmd.ExecuteReader()
If dt.DataRows.Count > 0 Then
Messagebox.show("已经存在数据!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Else
Messagebox.show("可以增加数据, !","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

这段代码是判断外部数据中有无数据同文本框一样的,如果有就提示有(也就是账号存在的意思),如果没有就提示没有.

--  作者:blackzhu
--  发布时间:2011/6/15 13:17:00
--  
Dim UserName As String = e.Form.Controls("账号1").Value

Dim cmd As New SQLCommand

Dim dt As datatable

cmd.C  

cmd.CommandText = "SELECT * From {xtuser} Where [用户账号] = \'"& username &"\'" 

dt = cmd.ExecuteReader()

If dt.DataRows.Count > 0 Then

Messagebox.show("账号已存在!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)

Else

Messagebox.show("账号不存在, !","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)

End If
[此贴子已经被作者于2011-6-15 13:17:47编辑过]

--  作者:blackzhu
--  发布时间:2011/6/15 13:19:00
--  
奇怪,外部数据源名称的那一段代码怎么出不出来的.


cmd.C

--  作者:blackzhu
--  发布时间:2011/6/15 13:19:00
--  
碰到鬼了.