Results 1 to 2 of 2

Thread: [RESOLVED] DataGridView Error

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Resolved [RESOLVED] DataGridView Error

    Hi,

    I am obviously doing something wrong. I am trying to hook up a search button so the user can search the database by last name. I have a textbox where the user types in the last name and then clicks search. Problem is that I keep getting an error that says (No value given for one or more required parameters.) referring to line- da.Fill(ds,"EmpAccessInfo") - when I use the following string:

    strSearch = "SELECT * FROM EmpAccessInfo WHERE LastN LIKE " & txtSRCH_LN.Text

    But it works fine and displays ALL the records when I use:

    strSearch = "SELECT * FROM EmpAccessInfo"

    Here is my code:

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim strSearch As String

    con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\AppAccess_tst3.mdb"
    con.Open()

    strSearch = "SELECT * FROM EmpAccessInfo WHERE LastN LIKE " & txtSRCH_LN.Text
    da = New OleDb.OleDbDataAdapter(strSearch, con)
    da.Fill(ds, "EmpAccessInfo")
    DataGridView1.DataSource = ds.Tables("EmpAccessInfo") ''DefaultViewManager


    con.Close()

    End Sub

    Not sure what I am doing wrong. Any help would be great.

    Thanks!

    Mac

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    31

    Re: DataGridView Error

    strSearch = "SELECT * FROM EmpAccessInfo WHERE LastN LIKE " & txtSRCH_LN.Text

    ERROR: Left out the single ' around txtSRCH_LN.text

    Working Code:
    strSearch = "SELECT * FROM EmpAccessInfo WHERE LastN ='" & txtSRCH_LN.Text & "'"

    Overlooked it.

Posting Permissions

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



Click Here to Expand Forum to Full Width