C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Binding Stored Procedures to Buttons


Posted Date: 05 Sep 2008      Total Responses: 2

Posted By: JSteele       Member Level: Bronze     Points: 1



I've got a Stored Procedure that I would like to fire when a specific button is clicked by the user.
In the stored procedure, I've created a variable @Query and built out the query into it using user-defined parameters. It is executed via:
'exec sp_executesql @Query'

Just wondering if it's possible to do this, and if so, how.

Thanks,
JS.





Responses

Author: Kapil Deo Malhotra    05 Sep 2008Member Level: GoldRating:     Points: 2

Hi,

You can call any stored procedure when ever you want. In Button Click event, create the Connection with database using ADO.Net objects. After establishing the connection create the SQLCommand object and you can call the SP using that Object.

Hope that helps.






Author: JSteele    05 Sep 2008Member Level: BronzeRating:     Points: 6

Hi,
My first post was overly vague, hopefully a bit more specification will make it clear what I'm trying to do.
I have a single DataGrid that I'm trying to populate with data from the database. I want this grid to be dynamic in that a different button click will fire different SELECTs and insert the appropriate data into the grid.
Here is one of the Stored Procedures I would like to use:

ALTER PROCEDURE dbo.GetInfo
(
@Filter varchar(max),
@Param varchar(max)
)
AS
Declare @Query nvarchar(max)
Set @Query = 'SELECT * FROM ClientInfo Where ' + @Filter + ' = ' + Char(39) + @Param + Char(39) + ' '
exec sp_executesql @Query

I want this to be executed when a specific button is clicked. Here is the onclick event for that button:

protected void Button1_Click(object sender, EventArgs e)
{
ClientDataSource.SelectCommand = "GetInfo";
ClientDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
ClientDataSource.SelectParameters.Add("Param", TypeCode.String, SearchBox.Text);
ClientDataSource.SelectParameters.Add("Filter", TypeCode.String, DropDownList1.SelectedValue);

}

Am I missing something?
Thanks again.
JS



Post Reply
You must Sign In to post a response.
Next : Linked Servers
Previous : Interview Questions
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use