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

  • Home
  • SEARCH
  • 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 7013255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:21:47+00:00 2026-05-27T22:21:47+00:00

I created the below method which i tested and does return the correct data.

  • 0

I created the below method which i tested and does return the correct data. Where I am confused is what is the proper way to populate individual textboxes on a form with the results from this method?

Rather than using an objectdatasource and then binding a gridview to the objectdatasource that works but I need more freedom to customize the form.

public MemberDetails GetMemberDetail(int membershipgen)
   {
       SqlConnection con = new SqlConnection(connectionString);
       SqlCommand cmd = new SqlCommand("usp_getmemberdetail", con);
       cmd.CommandType = CommandType.StoredProcedure;

       cmd.Parameters.Add(new SqlParameter("@MEMBERSHIPGEN", SqlDbType.Int, 5));
       cmd.Parameters["@MEMBERSHIPGEN"].Value = membershipgen;

       try
       {
           con.Open();
           SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);

           reader.Read();
           MemberDetails mem = new MemberDetails((int)reader["MEMBERSHIPGEN"], (string)reader["MEMBERSHIPID"], (string)reader["LASTNAME"],
                    (string)reader["FIRSTNAME"], (string)reader["SUFFIX"], (string)reader["MEMBERTYPESCODE"]);
           reader.Close();
           return mem;
       }
        catch (SqlException err)
       {
            throw new ApplicationException("Data error.");
        }
        finally
       {
           con.Close();
       }
  • 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-27T22:21:47+00:00Added an answer on May 27, 2026 at 10:21 pm

    Something along the lines of:

    var memberDetails = GetMemberDetail(12345);
    textBox1.Text = memberDetails.Prop1;
    textBox2.Text = memberDetails.Prop2;
    ...
    

    Also I would refactor this method and make sure that I properly dispose disposable resources by wrapping them in using statements to avoid leaking unmanaged handles:

    public MemberDetails GetMemberDetail(int membershipgen)
    {
        using (SqlConnection con = new SqlConnection(connectionString))
        using (SqlCommand cmd = con.CreateCommand())
        {
            con.Open();
            cmd.CommandText = "usp_getmemberdetail";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@MEMBERSHIPGEN", membershipgen);
            using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
            {
                if (reader.Read())
                {
                    return new MemberDetails(
                        reader.GetInt32(reader.GetOrdinal("MEMBERSHIPGEN")), 
                        reader.GetString(reader.GetOrdinal("MEMBERSHIPID")),
                        reader.GetString(reader.GetOrdinal("LASTNAME")),
                        reader.GetString(reader.GetOrdinal("FIRSTNAME")),
                        reader.GetString(reader.GetOrdinal("SUFFIX")),
                        reader.GetString(reader.GetOrdinal("MEMBERTYPESCODE"))
                    );
                }
                return null;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a DatePicker user control (ASP code below, no code behind) which is
I've created a simple parameterless stored procedure which I've pasted below. I've imported the
I have created TWO screens which i will paste the code below. `FirstScreen:` i
I have created button 2 below: <input id=Button1 type=button value=Stop onclick=alert('hello world');/> <input id=Button2
I've refactored how the merged-dictionary ( all_classes ) below is created, but I'm wondering
I have created one table using the below command: create table Table1( Id int
I created few user defined types in my database as below CREATE TYPE [dbo].[StringID]
I've created a stored procedure similar to the one below (I'm using this cut
I have created a file with printStream object as shown below. PrintStream outPutOffice =
I am trying to created nested dictionary variable like the below, But I get

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.