Retrieve data from sql (LOG IN)

nazri

Member
Joined
Mar 27, 2014
Messages
8
Location
Malaysia
Programming Experience
Beginner
hai, everyone.. i want to login data by clicking login button. my database name is Tbl_SysTestingSave.
my command after success login is enable the save button on right. because by default, i set the save button is enable = false
here is my simple form and the code.

testing.JPG


Imports System.Data.SqlClient

Imports OleDbAlias = System.Data.OleDb


Public Class Testing
Dim MyConnection As SqlConnection = New SqlConnection("Server=Unknown\LIVE;Database=Accounts;uid=sa;pwd=sa")
Dim MyDataAdapter As New SqlDataAdapter()
Dim conn As New OleDbAlias.OleDbConnection()


Private Const STR_PleaseFillTheRequiredBlankTextbox As String = "Please fill the required blank textbox"
Private Const STR_Then As String = " Then"
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveLoginButton.Click
If SaveNameTextBox.Text = "" Then
MsgBox("Please fill the Name", _
MsgBoxStyle.OkOnly, _
"Empty")
ElseIf SavepassTextBox.Text = "" Then
MsgBox("Please fill the Password", _
MsgBoxStyle.OkOnly, _
"Empty")
Else
obj_Sys.DB.SQL_INSERT(String.Format("Insert into Tbl_SysTestingSave(name,password) values ('{0}','{1}')", SaveNameTextBox.Text, SavepassTextBox.Text))
MessageBox.Show("Data Save")
End If


End Sub


Private Sub LoginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginButton.Click
'Dim ds As New DataSet
'obj_Sys.DB.SQL_SELECT("SELECT * FROM Tbl_SysTestingSave ORDER BY Name, Password", ds, "", False)
'For int_i As String = "" To ds.Tables(0).Rows.Count - 1
' If ds.Tables(0).Rows(int_i).Item("Name") = " " Then
' Dim parentnode As New TreeNode() With {.Name = ds.Tables(0).Rows(int_i).Item("NodeId").ToString & ds.Tables(0).Rows(int_i).Item("NodeDisplayName").ToString, .Tag = ds.Tables(0).Rows(int_i).Item("NodeId"), .Text = ds.Tables(0).Rows(int_i).Item("NodeDisplayName")}
' TreeView1.Nodes.Add(parentnode)


' For int_j As Integer = 0 To ds.Tables(0).Rows.Count - 1
' If ds.Tables(0).Rows(int_j).Item("ParentId") = ds.Tables(0).Rows(int_i).Item("NodeId") Then
' Dim childnode As New TreeNode() With {.Name = ds.Tables(0).Rows(int_j).Item("NodeId").ToString & ds.Tables(0).Rows(int_j).Item("NodeDisplayName").ToString, .Tag = ds.Tables(0).Rows(int_j).Item("NodeId"), .Text = ds.Tables(0).Rows(int_j).Item("NodeDisplayName")}
' parentnode.Nodes.Add(childnode)
' End If
' Next
' End If
'MyDataAdapter.SelectCommand = New SqlCommand()
'MyDataAdapter.SelectCommand.Connection = MyConnection




MyDataAdapter.SelectCommand.CommandText = String.Format("Select * FROM Tbl_SysTestingSave ((Name, Password) " & "='" & "{0}'AND Password = '{1}'", NameLoginTextbox.Text, loginPasswordTextBox.Text)
Dim Result As String


If NameLoginTextbox.Text = "" Then
MsgBox("Please fill the Name", _
MsgBoxStyle.OkOnly, _
"Empty")
ElseIf loginPasswordTextBox.Text = "" Then
MsgBox("Please fill the Password", _
MsgBoxStyle.OkOnly, _
"Empty")
ElseIf Result = NameLoginTextbox.Text And loginPasswordTextBox.Text Then
SaveInfoButton.Enabled = True
Else
MessageBox.Show("Username and Password do not match..", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If


End Sub
Private Sub SaveInfoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveInfoButton.Click
Dim ds As New DataSet
' '' obj_Sys.DB.SQL_INSERT(String.Format("Insert into Tbl_SysTestingSave(name,password) values ('{0}','{1}')", SaveNameTextBox.Text, SavepassTextBox.Text))
If InfoNameTextBox.Text = "" Then
MsgBox("Please fill the Name", _
MsgBoxStyle.OkOnly, _
"Empty")
ElseIf InfoICTextBox.Text = "" Then
MsgBox("Please fill the IC", _
MsgBoxStyle.OkOnly, _
"Empty")
Else
obj_Sys.DB.SQL_SELECT("SELECT ISNULL(MAX(ID),0)+1 AS ID FROM Tbl_SysTestingInfo", ds)
obj_Sys.DB.SQL_INSERT(String.Format("Insert into Tbl_SysTestingInfo(ID,Name,IC) values ('{0}','{1}','{2}')", ds.Tables(0).Rows(0).Item(0), InfoNameTextBox.Text, InfoICTextBox.Text))
MessageBox.Show("Data Save")
End If
End Sub
End Class
 
Top Bottom