‘ the user logs in using this button Private Sub btnLoginNow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoginNow.Click Try con.Open() With cmd .Connection = con .CommandText = "SELECT * FROM dbo.People WHERE UserName = '" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'" dr = cmd.ExecuteReader If (dr.Read() = True) Then MsgBox("User is valid") Me.Close() LoginAfter.Show() Else MsgBox("Invalid username or password!") End If 'If result = 0 Then ' MsgBox("Login attemp failed") 'Else ' MsgBox("Login successful") 'End If End With dr.Close() Catch ex As Exception MsgBox(ex.Message) Finally con.Close() End Try End Sub ‘creating and loading data 'creating CRUD create read update delete to database Public Sub CreateMethod(ByVal sql As String) Try 'open connection con.Open() 'hold the data With cmd .Connection = con .CommandText = sql 'execute the data result = cmd.ExecuteNonQuery dr = cmd.ExecuteReader If result = 0 Then MsgBox("No data save", MsgBoxStyle.Information) Else MsgBox("Data saved to the database") End If End With Catch ex As Exception MsgBox(ex.Message) End Try con.Close() End Sub 'holding the data to retrieve Public Sub Reload(ByVal sql As String) Try dt = New DataTable con.Open() With cmd .Connection = con .CommandText = sql End With Catch ex As Exception MsgBox(ex.Message) End Try con.Close() da.Dispose() End Sub Private Sub btnReload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReload.Click 'reload data from database Try Reload("SELECT * FROM dbo.People") FillTable(DataGridView1) Catch ex As Exception MsgBox(ex.Message) End Try End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)