 |
|
โค้ด ไฟล์ app.config ครับ
Code (VB.NET)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--<configSections>
</configSections>-->
<connectionStrings>
<add name="Project_RFIDConnectionString"
connectionString="Data Source=COMSCI-PC\SQLEXPRESS;Initial Catalog=Project_RFID;Persist Security Info=True;User ID=sa;Password=root"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>
อันนี้โค้ดฟอร์ม login ครับ หาหลายเว็บแล้วผมไม่เข้าใจเลย รบกวนช่วยแก้ด้วยนะครับ
Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Class LogInFrom
Public pUser_id As String = ""
Public pPassword As String = ""
Dim strConnString As String = ConfigurationManager.GetSection("Project_RFIDConnectionString")
Private Sub logIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles logIn.Click
Dim objDialogResult As New DialogResult()
If CheckBox_admin.Checked Then
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim strSQL As String
'strConnString = "Data Source=COMSCI-PC\SQLEXPRESS;Initial Catalog=Project_RFID;Persist Security Info=True;User ID=sa;Password=root"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM ADMIN WHERE ADM_USERNAME = '" & Me.userName.Text & "' AND ADM_PASSWORD = '" & Me.password.Text & "' "
objCmd = New SqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
If intNumRows > 0 Then
Dim frm As New Form_Admin
frm._strUser = Me.userName.Text
frm.LoadInfor()
frm.Show()
Me.Hide()
Else
objDialogResult = MessageBox.Show("คุณไม่สามารถลงชื่อเข้าใช้ระบบของผู้ดูแลระบบได้ กรุณาตรวจสอบข้อมูลอีกครั้ง", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
userName.Clear()
password.Clear()
userName.Focus()
End If
objConn.Close()
objConn = Nothing
Else
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim strSQL As String
'strConnString = "Data Source=COMSCI-PC\SQLEXPRESS;Initial Catalog=Project_RFID;Persist Security Info=True;User ID=sa;Password=root"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM ACCOUNT WHERE USERNAME = '" & Me.userName.Text & "' AND PASSWORD = '" & Me.password.Text & "' "
objCmd = New SqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
If intNumRows > 0 Then
Dim frm As New Form_User
frm._strUser = Me.userName.Text
frm.LoadInfor()
frm.Show()
Me.Hide()
Else
objDialogResult = MessageBox.Show("ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง กรุณาลองใหม่ หรือติดต่อผู้ดูแลระบบ", "Login Fail", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
userName.Clear()
password.Clear()
userName.Focus()
End If
objConn.Close()
objConn = Nothing
End If
End Sub
รบกวนด้วยนะครับ แก้ตรงไหนบ้าง
ขอบคุณล่วงหน้าครับ
Tag : .NET, Ms SQL Server 2005, Win (Windows App), VS 2008 (.NET 3.x), Windows
|
|
 |
 |
 |
 |
Date :
2012-09-25 12:08:25 |
By :
ultraman_ex |
View :
1723 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |