Help on getting an email address from the Membership table by USERID. RRS feed

  • Question

  • So I added a Data Access Layer to get some data. I added a query for getting the email address by UserId. Here is the query, which I think is right.


    SELECT LoweredEmail FROM dbo.aspnet_Membership WHERE UserId = @UserId


    Now getting the email address into a variable is where I am having issues.


    Here is what I have so far. I know it is wrong, because I am still getting back a DataTable. I think. And I can't assign a datatable to a string.


    I also tryed 'useremailaddsRow' instead of '', but obviously thats not right as well.


    Code Snippet


    // SELECT LoweredEmail FROM dbo.aspnet_Membership WHERE UserId = @UserId


    BizGearDataLayer.useremailaddsDataTable emailaddy2 = emailAdapter.GetDataByUserId(new Guid(strUserID));


    string strEmailAddress = emailaddy2.LoweredEmail;



    Sunday, February 10, 2008 1:19 AM



    If you still want the datatable the code should look something like:



    string strEmailAddress = emailaddy2[0].LoweredEmail;


    Since you get a row back you need to index that. But if you just want a single string you should add a method to the adapter that just returns a single value. That's the second option in the second step of the method wizard. This will create a method that uses executescalar to get your value.



    Sunday, February 10, 2008 9:34 AM