+ -
当前位置:首页 → 问答吧 → 新人用Vb2005建立了一个学生管理系统登录界面如下,验证密码出现问题。估计是dataset那。

新人用Vb2005建立了一个学生管理系统登录界面如下,验证密码出现问题。估计是dataset那。

时间:2011-12-07

来源:互联网

设计登录界面的时候需要账号和密码,我建立一个SQL数据库后跟VB的登录form链接成功,查询和链接都是用的sql控件,sqlconnection,sqldataAdapter,dataset,里面的查询语句写得是:
SELECT zh, mm
FROM mima
WHERE (zh = '&"me.TextBox1.Text"&') AND (mm = '&"me.TextBox2.Text"&')
期中zh,mm 为mima表里的字段。
当我用SqlDataAdapter1.Fill(DataSet11, 0, 90, "mima") :此处填充的时候好像没起作用。
  If DataSet11.Tables("Table").Rows.Count = 0 Then
  MsgBox("用户名或密码错误,请重新输入", vbMsgBoxSetForeground, "系统提示!!")
  TextBox1.Text = ""
  TextBox2.Text = ""
  Else
  Form2.Show()
  Me.Hide()
  End If
运行总是提示密码错误,我感觉就是fill函数,没有把mima表里的数据填充到dataset的lable里。
之后逐语句执行,发现了一个问题,代码如下:
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
  Global.System.ComponentModel.BrowsableAttribute(true), _
  Global.System.ComponentModel.DesignerSerializationVisibilityAttribute(Global.System.ComponentModel.DesignerSerializationVisibility.Visible)> _
  Public Overrides Property SchemaSerializationMode() As Global.System.Data.SchemaSerializationMode
  Get
  Return Me._schemaSerializationMode
  End Get
  Set Me._schemaSerializationMode = value
  End Set
  End Property



还是dataset里出错了,那个SET有问题,

作者: pepper_yi   发布时间: 2011-12-07

VB.NET code

dim ds as new dataset
sql="............."
'SELECT zh, mm FROM mima WHERE (zh = '&"me.TextBox1.Text"&') AND (mm = '&"me.TextBox2.Text"&')
dim cmd as new DataAdapter(sql,sqlconnectio1)
cmd.fill(ds,"mima")
If Ds.Tables("mima").Rows.Count = 0 Then
  MsgBox("用户名或密码错误,请重新输入", vbMsgBoxSetForeground, "系统提示!!")
  TextBox1.Text = ""
  TextBox2.Text = ""
  Else
  Form2.Show()
  Me.Hide()
  End If

作者: htpower   发布时间: 2011-12-07

- -~DataAdapter写错了~应该是SqlDataAdapter

作者: htpower   发布时间: 2011-12-07

按你的写法的话,If DataSet11.Tables("Table").Rows.Count = 0 Then
应该是:If DataSet11.Tables("mima").Rows.Count = 0 Then

作者: htpower   发布时间: 2011-12-07

问题已经解决了,改了方法,是从别人那看到的,代码如下,忘了那个大大的ID了。
 Dim i As Integer
  If RadioButton1.Checked = True Then
  cmd.CommandText = "select ano,apaswd,aname from admain"
  da.SelectCommand = cmd
  da.Fill(ds, "t1")
  For i = 0 To ds.Tables("t1").Rows.Count - 1
  If TextBox1.Text = ds.Tables("t1").Rows(i).Item(0) And TextBox2.Text = ds.Tables("t1").Rows(i).Item(1) Then
  Form5.Label1.Text = " Welcome!" & ds.Tables("t1").Rows(i).Item(2)
  pb = 1
  Form5.Show()
  Me.Hide()
  Exit For
  End If
  Next
但是我原来的那个fill问题还是没解决,问什么在sqlcommand里写的SELECT语句在带条件的时候就没起作用呢,dataset里就没有数据???我还得通过表单进行数据的插入删除,修改工作,这个不解决,以后的问题还很多。谢谢各位了,小弟的期末课程设计。

作者: pepper_yi   发布时间: 2011-12-07

热门下载

更多