locked
[Ignore!] Got some issues with my code RRS feed

  • General discussion

  • I would be greatly appreciated if someone could help me with my code, I have been struggling on how to make it work recently. I am also trying to write a search function but do not know how to successfully do so...

    Thanks,

    Robert

    Private Sub Login_button_click(sender As Object, e As EventArgs) Handles Login_Button.Click
    
    
            If Not String.IsNullOrEmpty(Password_Box.Text) Then
    
    
    
                Dim dt As New DataTable
                Using cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\bobby\Documents\DOFE App\Starting_App Access Database\Database.accdb;")
                    Using cmd As New OleDbCommand("", cn)
                        cmd.Parameters.Add("@id", OleDbType.LongVarChar)
    
    
                        cmd.CommandText =
                        <SQL>
                        SELECT 
                            [username, password]
                            
                        FROM 
                            information
                        
                    </SQL>.Value
                        cn.Open()
                        dt.Load(cmd.ExecuteReader())
    
    
    
                    End Using
                    Dim username_search As String = Username_Box.Text
                    Dim cmd As New SqlCommand("SELECT * FROM item WHERE broker_id Like '%" & SearchText & "%' ", con)
                End Using
            Else
                MessageBox.Show("Please supply some text for the search")
            End If
        End Sub




    • Changed type Robert -_- Tuesday, May 22, 2018 9:39 PM
    • Edited by Robert -_- Wednesday, May 23, 2018 5:33 AM
    Saturday, May 19, 2018 7:20 PM

All replies

  • cmd.Parameters.AddWithValue("?", Username_Input.Text)
    cmd.Parameters.AddWithValue("?", Password_Input.Text)

    Success
    Cor


    Saturday, May 19, 2018 7:29 PM
  • Hey Cor, thanks for the help, just looked and realized I have put the wrong code.. Could you have a look at the new one I have edited in.
    Saturday, May 19, 2018 8:51 PM
  • Rob, 

    I really don't know what you want to do with your current code. 

    I see something around a permission testing for this operation, but that does not go in this way. But I really don't know if it is meant like that. 

    Be aware that OleDB has no named parameters, and therefore every character or string fits. (and the question mark is then a kind of convention)


    Success
    Cor


    Sunday, May 20, 2018 10:30 AM
  • Cor,

    I am currently trying to create a system so that 2 inputs can be checked against a database and the answer can be returned

    Sunday, May 20, 2018 7:06 PM
  • One thing I would do is fix the brackets.

    SELECT [username], [password]


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, May 20, 2018 7:55 PM
  • Hey, 

    Thanks for the help all. I belive it is called a call and check function. I have been looking around and am considering using a indexOF to check the strings. I am currently trying to figure out how to write the call function, I dont know if what am was using is correct. If anyone wants to send me any adapted versions that would be great!

    Thanks,

    Rob

    Sunday, May 20, 2018 8:49 PM
  • Cor,

    I am currently trying to create a system so that 2 inputs can be checked against a database and the answer can be returned

    Hi Robert,

    According to your code, I find you want to get data from Access database, but you create sqlcommand here, I don't understand it, you also want to get data from sql database?

    You said that you want to input two value that will be check against from database, if yes, answer will returned.

     If Not String.IsNullOrEmpty(Password_Box.Text) Then
                Dim dt As New DataTable
                Dim commandtext As String = "select answer from infotmation where username=@username and password=@password"
                Using cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\bobby\Documents\DOFE App\Starting_App Access Database\Database.accdb;")
                    Using cmd As New OleDbCommand(commandtext, cn)
                        cmd.Parameters.AddWithValue("@username", Username_Box.Text)
                        cmd.Parameters.AddWithValue("@password", Password_Box.Text)
                        cn.Open()
                        dt.Load(cmd.ExecuteReader())
                    End Using
                End Using
            Else
                MessageBox.Show("Please supply some text for the search")
            End If

    Something like this.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 21, 2018 1:40 AM
  • Hi Cherry,

    I used your code, when i did so it displayed the message 'System.Data.OleDb.OleDbException: 'No value given for one or more required parameters.' Is there anything else I am doing wrong with my code? If not what is the problem and is there a way to solve it.

    Thanks,

    Robert

    Monday, May 21, 2018 5:49 PM
  • Cor,

    I am currently trying to create a system so that 2 inputs can be checked against a database and the answer can be returned

    Robert,

    You make it difficult to help you. You come with a problem, which is simple to answer. 

    I do and then you remove your whole text and code from the question and comes with complete different text and code. (Only the header stays the same)

    Do you know that if you want help people read what is already answered. And currently nobody understands what I replied. 

    Is it not more clever to solve first the first problem?


    Success
    Cor


    Tuesday, May 22, 2018 7:58 PM