Hi,
I am creating a feedback form where I want to show the Feedback id to the user after the user submits his data.With your help I have created the required Store Procedure.But I am not able to return the value to user,when i try to do it it gives a error stating that cannot use output in declare statement.How do I achieve this.Here's my SP and C#
create table tbl_feebback
(
Id int identity (1,1),
FeedbackId varchar(10),
[Message] varchar(max),
CreatedDate Datetime
)
Create PROCEDURE [dbo].[usp_UserFeedback]
@Message varchar(max)
AS
BEGIN
SET NOCOUNT ON;
BEGIN
DECLARE @AlphaId VARCHAR(10)
DECLARE @Count INT
SELECT @Count = COUNT(*) + 1 FROM tbl_feebback
SET @AlphaID = 'FB00' + LEFT(CAST(@Count AS VARCHAR(10)), 4)
INSERT INTO [tbl_feebback]
([FeedbackId]
,[Message]
,[CreatedDate]
)
VALUES
(@AlphaID
,@Message
,GETDATE()
)
END
END
Code Behind
protected void InsertFeedback(object sender, EventArgs e)
{
String constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection connection = new SqlConnection(constr))
{
SqlCommand command = new SqlCommand("usp_UserFeedback", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@Username", txtMessage.Text.Trim());
connection.Open();
command.ExecuteNonQuery();
}
}