Hello all,
Is it possible to pass query as a value to the stored procedure input parameter.
Printable View
Hello all,
Is it possible to pass query as a value to the stored procedure input parameter.
can u give a sample of what you want?
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.
what i want is can i pass the query directly to the stored procedure parameter, or is there any other way to do this.VB Code:
strSQL = "SELECT CustomerId FROM CustomerDetails Where CustomerName=" TextBox1.Text " sda = New SqlDataAdapter(strSQL, strConn) sda.Fill(ds, "CustomerDetails") If ds.Tables("CustomerDetails").Rows.Count = 0 Then CustomerId = 0 Else CustomerId = ds.Tables("CustomerDetails").Rows(0).Item("CustomerDtlsId") End If Cmd.Parameters.Add("@CustomerDtlsId", SqlDbType.VarChar).Value = CustomerId
Cmd.Parameters.Add("@CustomerDtlsId", SqlDbType.VarChar).Value="SELECT CustomerId FROM CustomerDetails Where CustomerName=" TextBox1.Text "
in my project i do this , just try
VB Code:
Sqlsel.CommandType = CommandType.StoredProcedure; Sqlsel.Parameters.Add(new MySqlParameter("?CustomerId",MySqlDbType.String,20)); Sqlsel.Parameters["?CustomerId"].Value = textBox1.Text;
i am not getting this where should i write the sql query
SELECT CustomerId FROM CustomerDetails Where CustomerName=?CustomerId
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
Can you please post me a line of code
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