求助VB.NET 做一个用户的登录界面 用SQL数据库
vb.net吧
全部回复
仅看楼主
level 1
astray310 楼主
第一次发帖,求助各位。现在准备用VB.NET做一个用户的登录界面,如果输入信息和数据库的符合就能进入系统的主界面。但是代码部分遇到了问题,来求助各位,谢谢。
贴上的图是我现在的进度,和数据库的设计。
2014年12月16日 09点12分 1
level 1
代码看起来有点繁琐。我稍改了下简洁些,我没建SQL数据库,你试试先:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim conn As New SqlClient.SqlConnection("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=x1;Password=x2;Initial Catalog=x3;Data Source=x4")
Dim Sql As String = "select * from 用户表 where 用户名 = '" & TextBox1.Text.Trim & "'"
Dim cmd As New SqlClient.SqlCommand(Sql, conn)
conn.Open()
Dim myreader As SqlClient.SqlDataReader = cmd.ExecuteReader
While myreader.Read
If TextBox2.Text <> myreader("密码") Then
MsgBox("密码错误!")
Else
Me.Hide()
Form2.Show()
End If
End While
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
2014年12月16日 10点12分 2
level 12
Public Class Form1
Const SqlConnectStr As String = "Data Source=(local);Initial Catalog=ZL;Integrated Security=True"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sConnect As New SqlConnection(SqlConnectStr)
Dim da As New SqlDataAdapter("select * from 客户登录 where kd_id='" + TextBox1.Text.Trim() + "' and kd_pwd='" + TextBox2.Text.Trim() + "'", sConnect)
Dim ds As New DataSet
da.Fill(ds, "客户登陆")
If ds.Tables(0).Rows.Count = 0 Then
MessageBox.Show("用户名或密码错误,请重新输入")
TextBox1.Focus()
Else
MsgBox(ds.Tables(0).Rows(0)("kd_id") & "登录成功")
Form2.Show()
Me.Hide()
End If
End Sub
2015年01月01日 16点01分 3
1