locked
Error message " No value given to one or more parameter" RRS feed

  • Question

  • Hi

    I am new to this type of work and have little idea what I am doing. I am currently getting error message " No values given to one or more parameter"  when I'm trying to retrieve data from access to Microsoft visual studio 2010. I want the user to be able to type something in textbox1 and then have the other 3 textboxes auto fill with the info its got from access. Would anyone be able to take a look at my code and see where I could be going wrong? I think its a connection issue between VB and access.

    Thanks in advance

    Code is - 

     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim con As New OleDb.OleDbConnection
            con.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Y:\Training Matrix\Training matrix database1.accdb")
            con.Open()
            Dim strsql As String
            strsql = " SELECT wsx, edc, rfv, tgb from qaz where wsx=" + TextBox1.Text
            Dim cmd As New OleDb.OleDbCommand(strsql, con)
            Dim myreader As OleDbDataReader
            myreader = cmd.ExecuteReader
            myreader.Read()
            TextBox1.Text = myreader("wsx")
            TextBox3.Text = myreader("tgb")
            TextBox4.Text = myreader("rfv")
            TextBox5.Text = myreader("tgb")
       
            con.Close()
        End Sub
    End Class
     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim con As New OleDb.OleDbConnection
            con.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Y:\Training Matrix\Training matrix database1.accdb")
            con.Open()
            Dim strsql As String
            strsql = " SELECT wsx, edc, rfv, tgb from qaz where wsx=" + TextBox1.Text
            Dim cmd As New OleDb.OleDbCommand(strsql, con)
            Dim myreader As OleDbDataReader
            myreader = cmd.ExecuteReader
            myreader.Read()
            TextBox1.Text = myreader("wsx")
            TextBox3.Text = myreader("tgb")
            TextBox4.Text = myreader("rfv")
            TextBox5.Text = myreader("tgb")
       
            con.Close()
        End Sub
    End Class

    Tuesday, September 15, 2020 7:20 AM

Answers

  • It is recommended to use “Parameterised queries”, but firstly try the next intermediate code too:

    . . .

    strsql = "SELECT wsx, edc, rfv, tgb from qaz where wsx= '" & TextBox1.Text & "'"

    Dim cmd As New OleDb.OleDbCommand(strsql, con)

    Dim myreader As OleDbDataReader

    myreader = cmd.ExecuteReader

    if myreader.Read() Then

       TextBox1.Text = myreader("wsx")

       TextBox3.Text = myreader("tgb")

       TextBox4.Text = myreader("rfv")

       TextBox5.Text = myreader("tgb")

    End If


    • Edited by Viorel_MVP Tuesday, September 15, 2020 8:12 AM
    • Marked as answer by lolbird1212 Tuesday, September 15, 2020 9:48 AM
    Tuesday, September 15, 2020 8:12 AM

All replies

  • It is recommended to use “Parameterised queries”, but firstly try the next intermediate code too:

    . . .

    strsql = "SELECT wsx, edc, rfv, tgb from qaz where wsx= '" & TextBox1.Text & "'"

    Dim cmd As New OleDb.OleDbCommand(strsql, con)

    Dim myreader As OleDbDataReader

    myreader = cmd.ExecuteReader

    if myreader.Read() Then

       TextBox1.Text = myreader("wsx")

       TextBox3.Text = myreader("tgb")

       TextBox4.Text = myreader("rfv")

       TextBox5.Text = myreader("tgb")

    End If


    • Edited by Viorel_MVP Tuesday, September 15, 2020 8:12 AM
    • Marked as answer by lolbird1212 Tuesday, September 15, 2020 9:48 AM
    Tuesday, September 15, 2020 8:12 AM
  • Hi, 

    This has solved the error code I was having but it now says "Syntax error"?

    Thank you for your time

    Tuesday, September 15, 2020 8:46 AM
  • Show your current code; maybe more adjustments are needed.

    Tuesday, September 15, 2020 9:01 AM
  • hi, 

    I have fixed the issue. The problem was I had a few random databases mapped and the program was getting confused so I removed all other database and issue was fixed once I added the changes you sent me. Thank you very much saved me lots of stress.

    Tuesday, September 15, 2020 9:48 AM