Results 1 to 9 of 9

Thread: [2005] Regarding stored procedure

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    [2005] Regarding stored procedure

    Hello all,

    Is it possible to pass query as a value to the stored procedure input parameter.

  2. #2

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding stored procedure

    i have 2 tables product and cutomer details , i want to store customerid in product table i created stored procedure for inserting into product table.
    Customer Name is the input field in my product form.
    i want to fetch the corresponding customerid and stored in product table.
    VB Code:
    1. strSQL = "SELECT CustomerId FROM CustomerDetails Where CustomerName=" TextBox1.Text  "
    2.         sda = New SqlDataAdapter(strSQL, strConn)
    3.           sda.Fill(ds, "CustomerDetails")
    4.         If ds.Tables("CustomerDetails").Rows.Count = 0 Then
    5.             CustomerId = 0
    6.         Else
    7.             CustomerId = ds.Tables("CustomerDetails").Rows(0).Item("CustomerDtlsId")
    8.         End If
    9.  
    10.         Cmd.Parameters.Add("@CustomerDtlsId", SqlDbType.VarChar).Value = CustomerId
    what i want is can i pass the query directly to the stored procedure parameter, or is there any other way to do this.

    Cmd.Parameters.Add("@CustomerDtlsId", SqlDbType.VarChar).Value="SELECT CustomerId FROM CustomerDetails Where CustomerName=" TextBox1.Text "

  4. #4
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: [2005] Regarding stored procedure

    in my project i do this , just try
    VB Code:
    1. Sqlsel.CommandType = CommandType.StoredProcedure;
    2. Sqlsel.Parameters.Add(new MySqlParameter("?CustomerId",MySqlDbType.String,20));
    3. Sqlsel.Parameters["?CustomerId"].Value = textBox1.Text;

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding stored procedure

    i am not getting this where should i write the sql query

  6. #6
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: [2005] Regarding stored procedure

    SELECT CustomerId FROM CustomerDetails Where CustomerName=?CustomerId

  7. #7
    Lively Member
    Join Date
    Feb 2005
    Posts
    121

    Re: [2005] Regarding stored procedure

    You can pass a query to Store procedure as input parameter and get this parameter in a variable of datatype nvarchar.

    Then in that stored procedure run like this

    exec sp_executesql <your variable>

    I hope this will help

    -Sachien

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding stored procedure

    Can you please post me a line of code

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding stored procedure

    This part is in sql server 2005

    declare @sql as nvarchar(500)

    insert into product(ProductName,customerId)values(@productName,@CustomerId)


    how can i pass sqlquery to @sql parameter from the codebehind file of asp.net 2.0.how can i take the value passed or query passed from front end in sql server 2005.

    after that i need to execute that query store the result in @customerid and pass that @customerid to the insert statement of the product table.

    Please help me to solve this

    Thanks in advance

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