Imports System.Data.Odbc
Imports System.Data
Imports System.Data.OleDb
Partial Class Login
Inherits System.Web.UI.Page
Dim conn As OdbcConnection
Dim strcon As String
Dim strSQL As String
Dim a As Boolean = False
Private Sub connectODB()
strcon = "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=1;Excel 8.0; DBQ=D:\\nicha\\MachineList.xls"
conn = New OdbcConnection(strcon)
conn.Open()
End Sub
Protected Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
connectODB()
Dim da As OdbcDataAdapter
Dim ds As DataSet = New DataSet
Dim i As Integer = 0
If txtUser.Text = "" Or txtPass.Text = "" Then
If txtUser.Text = "" Then
MsgBox("Please Enter User")
End If
If txtPass.Text = "" Then
MsgBox("Please Enter Password")
End If
ElseIf txtUser.Text <> "" Or txtPass.Text <> "" Then
strSQL = "SELECT * FROM [Sheet2$] " ' WHERE username = '" & txtUser.Text & "' " 'and pass = '" & txtPass.Text & "'"
da = New OdbcDataAdapter(strSQL, conn)
da.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
Do
If txtUser.Text <> ds.Tables(0).Rows(i)(0) And txtPass.Text <> ds.Tables(0).Rows(i)(1) Then
a = False
Else
a = True
End If
i = i + 1
Loop While txtUser.Text = ds.Tables(0).Rows(i)(0) And txtPass.Text = ds.Tables(0).Rows(i)(1)
If a = False Then
MsgBox("Change Password")
ElseIf a = True Then
MsgBox("OK")
End If
End If
conn.Close()
End Sub
End Class