Hello,
On my website i am trying to get my site to display the users address details if they are logged in have tried a stored procedure:

ALTER PROCEDURE dbo.showAddress
    @userid nvarchar(256)
AS
    SELECT Fullname, Address, County, Postcode FROM Addresses WHERE @userid = UserId
RETURN

But i get an area about expecting the user id? I have tried inserting through code behind:

protected void Page_Load(object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        SqlCommand oCMD = new SqlCommand();
        SqlConnection oCON = new SqlConnection();
        oCON.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
        oCON.Open();
        oCMD.Connection = oCON;
        oCMD.CommandType = CommandType.StoredProcedure;
        oCMD.CommandText = "showAddress";

        SqlDataReader oRDR = oCMD.ExecuteReader();
        oRDR.Read();
        txtName.Text = oRDR.GetString(oRDR.GetOrdinal("Fullname"));
        oCON.Close();
    }
}

But this doesnt work either for me. Is there some code that could be entered as something like:

txtPostcode.Text = "sql connection; Addresses; Fullname";

Any help or ADVICE is appreciated....

You need to set a Parameter for the userid. Look up SqlParameter on msdn.

I have figured out that my code in fact is working! BUT... The issue seems to be that when a user registers for my site using the CreateUserWizard and this encrypts the username and password, so when my program looks into database for the username it finds the encrypted text and this oviously doesnt match! So i need to either decrypt the code or never encrypt as it goes into databse table! Hmmm...

nvm just noticed this post is a month old

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.