Login form

nazri

Member
Joined
Mar 27, 2014
Messages
8
Location
Malaysia
Programming Experience
Beginner
Hi, anybody know how to retrieve data from sql to visual basic 2008?
This is my coding for save to sql :
obj_Sys.DB.SQL_INSERT(String.Format("Insert into Tbl_SysTestingSave(name,password) values ('{0}','{1}')", SaveNameTextBox.Text, SavepassTextBox.Text))

i want to login name and password from same textbox but different button​


 
Firstly, please don't hijack other people's threads. I have deleted your other post.

Secondly, please don't bump your threads, especially after only a matter of minutes. Everyone here is a volunteer so not at your beck and call. Also, we are all over the world, in various time zones. If noone happens to be online when you post your question then you wait. Even if noone answers for hours you still do not bump your thread. It will still be visible to people when they visit the forum so there's justification for you to push it back to the top of the queue. Your question is no more (or less) important then everyone else's. If the question has gone unanswered for a day ro two then you STILL do not simply bump it, but rather consider why noone has answered and try to provide more information or rephrase the question.

As for the code you posted, that is not your code to save the data. That's your code to invoke a method that contains the code to save the data. That same obj_Sys.DB object should have one or more methods for retrieving data too. Did you create that class yourself? If not then who did and did they include code for retrieving? If you did then where did you learn to write the code to insert new records? One would expect that that same resource would provide other data-access information as well, like how to retrieve.

Anyway, here's a link to some of my own ADO.NET code examples, which includes all the most common scenarios:

Retrieving and Saving Data in Databases

Note that all those examples use parameters, which you should too, instead of that horrible literal string method you're using at the moment. To learn why and how, you should read this:

Using Parameters in ADO.NET

To see how I recommend implementing a login form (which should absolutely not double as a registration form) check this out:

WinForms Login
 
tq for response. im sorry. i was new here..

like this.

testing.JPG

this is my simple form. (please dont comment it) just practice. im going to put data at both textbox above save button.
then i want to login back data from both textbox data below button save. Im looking the coding that can i write at login button. This is my coding. :


Imports System.Data.SqlClient
Public Class Testing
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
If NameLoginTextbox.Text = "" Then
MsgBox("Please fill the Name", _
MsgBoxStyle.OkOnly, _
"Empty")
ElseIf loginPasswordTextBox.Text = "" Then
MsgBox("Please fill the Password", MsgBoxStyle.OkOnly, "Empty")
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
 
Firstly, please don't hijack other people's threads. I have deleted your other post.

Secondly, please don't bump your threads, especially after only a matter of minutes. Everyone here is a volunteer so not at your beck and call. Also, we are all over the world, in various time zones. If noone happens to be online when you post your question then you wait. Even if noone answers for hours you still do not bump your thread. It will still be visible to people when they visit the forum so there's justification for you to push it back to the top of the queue. Your question is no more (or less) important then everyone else's. If the question has gone unanswered for a day ro two then you STILL do not simply bump it, but rather consider why noone has answered and try to provide more information or rephrase the question.

As for the code you posted, that is not your code to save the data. That's your code to invoke a method that contains the code to save the data. That same obj_Sys.DB object should have one or more methods for retrieving data too. Did you create that class yourself? If not then who did and did they include code for retrieving? If you did then where did you learn to write the code to insert new records? One would expect that that same resource would provide other data-access information as well, like how to retrieve.

Anyway, here's a link to some of my own ADO.NET code examples, which includes all the most common scenarios:

Retrieving and Saving Data in Databases

Note that all those examples use parameters, which you should too, instead of that horrible literal string method you're using at the moment. To learn why and how, you should read this:

Using Parameters in ADO.NET

To see how I recommend implementing a login form (which should absolutely not double as a registration form) check this out:

WinForms Login



Im sorry.. i still dont understand.. because im new to visual basic.Can you help me sir. Please.. i really need your help. guide me
 
hai, everyone.. this is my code... but still doesnt work.
i want to login data by clicking login button. from same db that i store data.. which is when i click save button.
my command after success login button is enable the save button on right. because by default, i set the save button is enable = false

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
 
Back
Top