Results 1 to 9 of 9

Thread: passing parameters in selectcommand

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    passing parameters in selectcommand

    While updating it passes parameters with updatecommand from dataset

    How can it be done in selectcommand

    passing parameters from dataset ?

  2. #2
    Junior Member ost's Avatar
    Join Date
    Jan 2004
    Posts
    19
    try explaining yourself a litle bit more :-)

    or post your code..

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    passing parameters in selectcommand

    I mean before loading data I want to type in the textboxes
    and use these as crietria from select command

  4. #4
    Member
    Join Date
    Mar 2004
    Posts
    39
    Hi!

    The dataadapter has a SelectCommand and the selectcommand has a parameter collection. So either add the parameter in design time or at run time and change the selectcommand to include a WHERE clause like "WHERE ContractID = @ContractID" where @ContractID is the name of the parameter.

    Ofcourse you also have to pass a value to the parameter before trying to fill the dataset.

    Code:
    daContract.SelectCommand.Parameters("@ContractID").Value = txtContractID.Text
    /Nisse

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    passing parameters in selectcommand

    Yes I did so but it is not accepting the parameters

  6. #6
    Member
    Join Date
    Mar 2004
    Posts
    39
    Did you define the parameter first?

    Either by "dim":ing it, and adding it to the parameters collection? or selecting the data-adapter, check the selectcommand property and there create a parameter?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    passing parameters in selectcommand

    I made the changes in sql statement

    select * from ......
    where fld1=?....

    and it autometically created the parameter but it gave error that it couldn't bind to the parameter?

  8. #8
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    How about something like this..

    Code:
    Public Sub SelectRecords()
            Dim MyConnection As New SqlClient.SqlConnection
            Dim myCommand As New SqlClient.SqlCommand
    
    
            myCommand.Parameters.Add(New SqlClient.SqlParameter("@CustomerID", TextBox1.Text))
    
            myCommand.CommandText = "SELECT * FROM MyTable WHERE CustomerID=@CustomerID"
            myCommand.Connection = MyConnection
    
    
        End Sub
    I find that parameters work better using the SqlClient.SqlCommand instead of the OLEDB.OLEDBCommand

    HTH

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    222

    passing parameters in selectcommand

    Thanks .
    It works fine.but it gives error if I use master detail relationed form.

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