dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] vb.net No value for one or more parameters

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    204

    Resolved [RESOLVED] vb.net No value for one or more parameters

    Hello,
    I am trying to pass an integer value but I kept getting the "No value for one or more parameters." when I set a breakpoint I noticed that there is no value in the Underline stuID below. Could you please look at my code I tell me what I am missing.
    Dim stuID As Integer
    stuID = Integer.Parse(txtId.Text)
    Dim myconnection As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Vb.Net Security\SecurityGuard\SecurityGuardmdb.accdb;Persist Security Info=False"
    Dim conn As New OleDbConnection
    conn.ConnectionString = myconnection
    conn.Open()

    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Studenttbl] WHERE [StudentIDtbl] = stuID or [LastNametbl] = '" & txtLastName.Text & "'", conn)
    Dim dr As OleDbDataReader = cmd.ExecuteReader
    Thanks helping

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,919

    Re: vb.net No value for one or more parameters

    You need to concatenate the stuID variable into the string just like you concatenated the textbox.Text into the string. The way you wrote it, the SQL parser is trying to interpret the token "stuID" to be meaningful to the database, which it isn't. It should look like this:

    WHERE [StudentIDtbl] = " & stuID.ToString & " or .... etc.

    However, you should really be using a parameterized query, because directly concatenating user supplied text into a query string, as you do when you concatenate in txtLastName.Text opens you up to SQL Injection exploits. That's a different matter, though, as is the problem with Integer.Parse.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    204

    Re: vb.net No value for one or more parameters

    Thanks, I made the changes and everything was fine. Also thanks for your advice about parameterize query

    AL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width