CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2015
    Posts
    5

    [RESOLVED] OleDbException Unhandled (No value given for one or more required parameters.)

    Hello ! I am making a project on Railway reservation system in which I want the user should have access to his booking history . The following code access records from two tables in the database . When I run this code for only one table ( accessing records from one table ) , it works fine but when I run this code for two tables , it gives me an error saying OleDbexception was unhandled ( No values given for more required parameters ) at
    Code:
       da.Fill(ds, "Table2")
    I know this line is wrong , because it is only for one table but I don't know how to do it for two tables . Please help ! Thank you ! This is my full code
    Code:
     
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            MyConn = New OleDbConnection
            MyConn.ConnectionString = connString
            ds = New DataSet
            tables = ds.Tables
            da = New OleDbDataAdapter("Select P.Tnumber, P.Name , P.Age ,T.PNR_Number,  P.Train_Name , P.SeatNo , P.Berth , P.Coach_Number , T.Starting_Point , T.Destination , T.Departure , T.Arrival , T.Fare From Table1,Table2 Where P.Train_Name = T.Train_Name and P.Phone= TextBox1.Text ", MyConn)
            da.Fill(ds, "Table2")
    
            Dim view As New DataView(tables(0))
            source1.DataSource = view
            DataGridView1.DataSource = view
    Actually , in my project , I want the user to type his phone number and based on the phone number entered by the user , the records from the database will be matched and displayed in the datagridview . Please help !

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: OleDbException Unhandled (No value given for one or more required parameters.)

    Code:
    P.Phone= TextBox1.Text "
    This part is a problem 1 because it is using the literal text "TextBox1.Text" rather than the contents and 2 because that is a string and is not in quotes.
    Assuming that the field is a text field in the DB then it must have quotes around it in your SQL
    The variable must also be outside the double quotes so that you get the value rather than the literal

    Like
    Code:
    P.Phone= '" & TextBox1.Text & "'"
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Apr 2015
    Posts
    5

    Re: OleDbException Unhandled (No value given for one or more required parameters.)

    Thanks for replying ! I changed the code but it still gives me the same error !
    Code:
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            MyConn = New OleDbConnection
            MyConn.ConnectionString = connString
            Using cmd As OleDbCommand = MyConn.CreateCommand
                ds = New DataSet
                tables = ds.Tables
                Using da As New OleDbDataAdapter
                    cmd.CommandText = "Select  P.[Tnumber] ,P.[Name] ,P.[Age] ,T.[PNR_Number],P.[Train_Name] ,P.[SeatNo] ,P.[Berth] ,P.[Coach_Number],  T.[Starting_Point] , T.[Destination] , T.[Departure] , T.[Arrival] , T.[Fare]  From Table1 As P INNER JOIN Table2 As T ON P.[Train_Name] = T.[Train_Name] WHERE P.[Phone] = ?"
    
                    Try
                        cmd.Parameters.AddWithValue("p1", TextBox1.Text)
                        da.SelectCommand = cmd
                        da.Fill(ds, "Table2")
                        Dim view As New DataView(tables(0))
                        source1.DataSource = view
                        DataGridView1.DataSource = view
    
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
    
    
                End Using
            End Using
    
        End Sub

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: OleDbException Unhandled (No value given for one or more required parameters.)

    Does the textbox contain something at the time of the error?
    Are your tables actually named Table1 and Table2?
    Which line is giving the error?
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Apr 2015
    Posts
    5

    Re: OleDbException Unhandled (No value given for one or more required parameters.)

    Thanks ! Ii works now . I was doing some spelling mistake .

Tags for this Thread

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

Featured