stored procedure to SQL DataSource
I have a stored procedure which combines values from 2 tables. This is the stored procedure:
ALTER PROCEDURE dbo.SplitTime
@time nvarchar(50),
@classid nvarchar(50)
AS
/* SET NOCOUNT ON */
DECLARE @delimiter char(1)
DECLARE @index INT
DECLARE @value nvarchar(4000)
SET @index = 1
SET @delimiter='-'
WHILE @index != 0
BEGIN
SELECT @index = CHARINDEX(@Delimiter,LTRIM(@time))
IF @index !=0
SELECT @value = LTRIM(LEFT(@time,@index - 1))
ELSE
SELECT @value = LTRIM(@time)
SET @value = LTRIM(RTRIM(@value))
IF @value <> ''
INSERT into StartEndTimes(times,ID) values(LTRIM(@value),@classid)
SELECT @time =LTRIM(RIGHT(@time,LEN(@time) - @index))
IF LEN(@ti开发者_Go百科me) = 0 BREAK
END
SELECT * from StartEndTimes,ClassInfo
So, basically I split the time which is of format 6:00 - 9:00 and store it in another table. Now, I need to assign this stored procedure to a sqldatasource in asp.net. But I'm not sure how to send the parameters. Both the parameters come from ClassInfo table. Can you please help me?
Take a look at https://web.archive.org/web/20211020133929/https://www.4guysfromrolla.com/articles/050207-1.aspx which covers some of the basics on using ASP.NET datasources.
However it looks from your stored procedure that you want to pass two parameters to the procedure, which inserts to a database and then returns results? If so, that doesn't seem like it's something you'll want to do and should split it into the insert and another separate one for the select.
At any rate, if you want to pass two parameters to a SqlDataSource for inserting you can do something like
<asp:SqlDataSource ID="MyCommand" runat="server" ConnectionString="Your connection string"
InsertCommand="SplitTimes" InsertCommandType="StoredProcedure">
<InsertParameters>
<asp:Parameter Name="time" PropertyName="String" />
<asp:Parameter Name="classid" PropertyName="String" />
</InsertParameters>
</asp:SqlDataSource>
You'll need to do some more work and get this control to work with a form, but that's the jist of it.
精彩评论