Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good day guys. I want to return a single value from the database. I want to display the retrieved value in a textbox where the stored procedure parameter comes from the selected index of a gridrow. For some reason it is not showing

What I have tried:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //string txtSession = " ";
                if (Session["IDNumber"] == null)
                {

                }

                else
                {
                    string Id = Session["IDNumber"].ToString();
                    bll = new BusinessLogicLayer();

                    try
                    {
                        doc = new Docket();

                    }

                    catch (Exception)
                    {

                    }

                }
            }

protected void grdInvolvedDockets_SelectedIndexChanged(object sender, EventArgs e)
        {
            doc = new Docket();
            bll = new BusinessLogicLayer();
            Session["DocketName"] = grdInvolvedDockets.SelectedRow.Cells[1].Text;
            doc.DocketName = Session["DocketName"].ToString();
            bind(doc);

           
        }

        public void bind(Docket doc)
        {
            doc = new Docket();
            using (SqlConnection con = new SqlConnection("Data Source=KEVIN-PC;Integrated Security=true;Initial Catalog=E-Docket1"))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("spLoadDevelopment", con);
                string result = Session["DocketName"].ToString();
                doc.DocketName = result;
                SqlParameter param = new SqlParameter("@DocketName", doc.DocketName);
                cmd.Parameters.AddWithValue("@DocketName", doc.DocketName.ToString());
                string new1;
                new1 = cmd.ExecuteScalar().ToString();





                //lblDetails.Text = result;
            }

        }


My stored procedure is a simple one and it looks like this

SQL
ALTER PROCEDURE [dbo].[spLoadDevelopment] 
	-- Add the parameters for the stored procedure here
	@DocketName varchar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT [Development]
	FROM DOCKET
	WHERE DocketName = @DocketName
END
Posted
Updated 23-Oct-17 0:17am
v2
Comments
PIEBALDconsult 21-Oct-17 19:07pm    
Why would you use a stored procedure to do that? An inline table-valued function would do the same thing and be more flexible.
KevinClaassens 21-Oct-17 21:36pm    
Would you please be able to show me how it is done? I needed a way to display some text depending on which column is selected and this is how far I came
Richard MacCutchan 22-Oct-17 3:10am    
Just inline the SELECT statement into your code. There is really no point in a stored procedure for such a simple command.
Karthik_Mahalingam 23-Oct-17 2:21am    
keep a break point and check where it is going wrong.
what is the value in "doc.DocketName"
Richard Deeming 24-Oct-17 13:26pm    
Might be something to do with the fact that, after storing the value returned from the stored procedure in the local variable new1, you throw that variable away without doing anything with it!

If you want to display the value returned from the stored procedure, then you're going to need to do something with it.

1 solution

ALTER PROCEDURE [dbo].[spLoadDevelopment]
-- Add the parameters for the stored procedure here
@DocketName varchar(50)
@Development varchar(50) OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT @Development = [Development]
FROM DOCKET
WHERE DocketName = @DocketName
END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900