CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Posts
    4

    Passing SP parameters

    Hello,

    how do I pass parameters to a stored procedure using OLEDB? (sql server 2000)

    I want the user to be able to enter query parameters in a text box and have those values passed in the "exec stored procedure" string.

    Thanks,

    J

  2. #2
    Join Date
    Apr 2002
    Location
    Haryana, India
    Posts
    198
    Hello

    There are two ways using which we can execute SP with parameters:

    1. Add value of parameters with spname in the SQL String like as follows:

    EXECUTE spName 'Param1', param2, 'Param3'

    Prefix and suffix single quote with parameter value if its type is string or date type.

    2. Or by following method:

    Dim connectionSql As new SqlConnection(connectionString)
    Dim commandSql As New SqlCommand()
    Dim parameterSql As SqlParameter
    Dim count As Integer

    With commandSql
    .Connection = connectionSql
    .CommandText = spName
    .CommandType = CommandType.StoredProcedure
    .Parameters.Clear()
    For count = 0 to Num ' Num means Number of parameters
    parameterSql = New SqlParameter()
    With parameterSql
    .ParameterName = "@ParamName"
    .Direction = System.Data.ParameterDirection.Input
    .SqlDbType = SqlDbType.VarChar
    .Value = ParamValue
    End With
    commandSql.Parameters.Add(parameterSql)
    Next
    .Execute
    End With

    Hope this will solve your problem.
    Enjoy,

    Gurdarshan Singh
    L.S.E. (Project Lead)
    InterGlobe Technologies Pvt. Ltd.
    Mobile #: 9891397798 (India)
    [email protected]
    [email protected]

    Always Think Positive whatever may be the Situation.

    Please rate my suggestion/response if you find it suitable or fulfill your requirement.

  3. #3
    Join Date
    Jan 2003
    Posts
    4

    Mostly ...

    Hello,

    Thanks for the reply. I understand how to send them, is it possible to load the results into a datatable?

    With my current code I have this:

    Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
    dataAdapter.Fill(dt)
    dataAdapter.Dispose()

    It appears your code doesn't make use of a datatable.

    Thanks again.

    Jeff

  4. #4
    Join Date
    Apr 2002
    Location
    Haryana, India
    Posts
    198

    Passing parameter for SP

    Hello,

    I think you haven't gone through different types of calling method of the Update method of the SQLDataAdapter.

    you can pass DataSet or DataTable or DataView as first parameter in the SQLDataAdapter object.

    Hope this will clear you about usage of SQLDataAdapter.
    Enjoy,

    Gurdarshan Singh
    L.S.E. (Project Lead)
    InterGlobe Technologies Pvt. Ltd.
    Mobile #: 9891397798 (India)
    [email protected]
    [email protected]

    Always Think Positive whatever may be the Situation.

    Please rate my suggestion/response if you find it suitable or fulfill your requirement.

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