Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5948835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:09:53+00:00 2026-05-22T17:09:53+00:00

Hi I have a stored procedure and a connection to the database. I have

  • 0

Hi I have a stored procedure and a connection to the database. I have other similar code on my website that works just fine but for the life of me I cannot get this to work. I want the username of the person logged in to be passed as a parameter. I can get it stored in a session variable.
I wasnt sure how to transfer it from the session variable to the parameter so I put it into a label and sent it that way. It shows that it is getting that far but everytime I just get the message ‘nothing found’
I have checked the stored procedure and that seems fine to me. Below is the code and stored procedure! please help!

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using System.Web.UI;
        using System.Web.UI.WebControls;
        using System.Web.Security;
        using System.Data.SqlClient;
        using System.Configuration;
        using System.Data;

        public partial class RescueOnlyPages_EditRescueDetails : System.Web.UI.Page
        {
            protected void page_PreInit(object sender, EventArgs e)
            {
                MembershipUser user;
                try
                {
                    if (User.Identity.IsAuthenticated)
                    {
                        // Set theme in preInit event
                        user = Membership.GetUser(User.Identity.Name);
                        Session["user"] = user;
                    }

                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                    //Log error here

                    // We have set theme in web.config to Neutral so if there is
                    // an error with setting themes, an incorrect theme wont be displayed to a customer

                }


            }
            protected void Page_Load(object sender, EventArgs e)
            {
                userLabel.Text = Session["user"].ToString();

                SqlDataReader myDataReader = default(SqlDataReader);

                SqlConnection MyConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["RescueAnimalsIrelandConnectionString"].ConnectionString);

                SqlCommand command = new SqlCommand("sp_EditRescueDetails", MyConnection);    

                if (!User.Identity.IsAuthenticated)
                {
                }
                else 
                {
                    command.Parameters.AddWithValue("@user", userLabel.Text.Trim());

                }

                 try
               {
                MyConnection.Open();
                command.CommandType = CommandType.StoredProcedure;

                myDataReader = command.ExecuteReader(CommandBehavior.CloseConnection);
                myDataReader.Read();


                GridViewED.DataSource = myDataReader;
                GridViewED.DataBind();

                if (GridViewED.Rows.Count >= 1)
                {

                    GridViewED.Visible = true;
                    lblMsg.Visible = false;           

                }
                else if (GridViewED.Rows.Count < 1)
                {
                    GridViewED.Visible = false;

                    lblMsg.Text = "Your search criteria returned no results.";
                    lblMsg.Visible = true;
                }





                MyConnection.Close();
               }
                 catch (SqlException SQLexc)
                 {
                     Response.Write("Read Failed : " + SQLexc.ToString());
                 }
            }


            }

stored procedure

 ALTER PROC [dbo].[sp_EditRescueDetails]
(
   @user nvarchar(50)

 )
 AS
 BEGIN


 SELECT [PostalAddress], [Telephone_No], [Website], [Email] 
 FROM [RescueDetails] 
 Where   [UserName] = @user 
 End

EDIT *
If I change the stored procedure and delete the
‘ Where [UserName] = @user ‘
line it brings in every user detail without any problem so I think it maybe something with this line or the
command.Parameters.AddWithValue(“@user”, userLabel.Text.Trim());
line that is causing me the problems

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:09:54+00:00Added an answer on May 22, 2026 at 5:09 pm

    Try setting

    command.CommandType = CommandType.StoredProcedure;
    

    before

     MyConnection.Open();
    

    Also don’t call myDataReader.Read(); if you are going to set the myDataReader as the data source for gridview. That will make it skip a row and if result has only one row then the grid will display nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database stored procedure call that, among other columns, returns a column
I have stored procedure in my database and i need to look up a
I have a stored procedure that has the parameter: @desk VARCHAR(50) I want to
I have this stored procedure that I want to use for my SAP crystal
I have a stored procedure that returns data in the format of: Date |
Afternoon All, I have a stored procedure in an SQL 2005 database named GasNominationsRawData_Insert.
I have Visual Studio .Net project which uses ADO connection to call stored procedure
I have created a method that can be called using a stored procedure name
I have an XML stored in the database table that I am trying to
I have a stored procedure made in Oracle 9g that returns a cursor with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.