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 6640215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:38:48+00:00 2026-05-25T23:38:48+00:00

I am trying to form a text representation of a table based off of

  • 0

I am trying to form a text representation of a table based off of the result coming in from a SqlDataReader.

while (unitsRdr.Read())
{
    note.AppendFormat("{0,-15}", String.Format("{0}({1})", unitsRdr.GetValue(0), unitsRdr.GetValue(1)));
}

Now what I expect to happen is I should get 4 sets of items, that will have padding on the right hand side equal to 15. Like this

BP(mm\Hg)      HR(bpm)        RR(rpm)        Sa O2(%)       |<-- this would be the end of the string.

However what I am getting is

BP(mm\Hg          )HR(bpm            )RR(rpm            )Sa O2(%              )|<-- this is the end of the string.

It appears to start counting after the ( and the ) is put after the number of spaces.

What is the correct way of doing formatting so the text is like my first example?


For anyone who wants it here is the source table

desc         unit
------------ ----------
BP           mm\Hg     
HR           bpm       
RR           rpm       
Sa O2        %         
  • 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-25T23:38:48+00:00Added an answer on May 25, 2026 at 11:38 pm

    I strongly suspect that the problem is that the value returned by unitsRdr.GetValue(1) is actually longer than you believe. I very much doubt that string.Format is doing that. Try using unitsRdr.GetValue(1).Trim() instead – or just test it with a hard-coded literal value.

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

Sidebar

Related Questions

I'm trying to change the form action based on the selected value from a
I am trying to do something of the form: alt text http://img707.imageshack.us/img707/4317/eswdbetcywhxebxvnhyqhzb.png Is it
I'm trying to add a plain text node in a zend form - the
I am trying to build a form where users can add a text field
I'm trying to edit a textbox's text in a Page_Load form on an ASP.NET
I'm trying to use SSIS to extract XML representation of a query result set
I am trying to have a form of text inputs. All inputs will in
I'm trying to bind a Textbox.Text to Form.Text (which sets the title of the
I am following alloy-complex-form-examples from github trying to learn nested forms and I just
What I'm trying to do is this: In text form: XXX Some text here

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.