| Author: Kapil Deo Malhotra 05 Sep 2008 | Member Level: Gold | Rating: 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 2008 | Member Level: Bronze | Rating: 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
|