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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:02:22+00:00 2026-06-11T09:02:22+00:00

I am developing a C# application in my company. The application uses a SQL

  • 0

I am developing a C# application in my company.
The application uses a SQL Server database via ADO .Net.
The application uses the ADO .Net data provider for SQL Server shipped with the .Net framework 4.

We are facing a problem when inserting a string programmatically into a varchar field.

Example

Let’s consider the database table named MY_TABLE with the following columns :

  • MY_FIRST_COL int
  • MY_SECOND_COL varchar(250)

I insert a record (REC1) into MY_TABLE by executing the following SQL query within SS Management Studio :

insert into MY_TABLE (1, "");

Then I select REC1 by using SSMS.
Then I copy the string contained in MY_SECOND_COL field.
Then I paste the string into Notepad++.
I notice the string is made up of 0 characters.
OK it makes sense !

Now I insert programmatically a record (REC2) into MY_TABLE by using an SqlCommand object.

Here is the string contained in the CommandText property :

insert into MY_TABLE (@p0, @p1);

Here are some values contained in properties of the SqlParameter object corresponding to the second parameter :

  • DbType : System.Data.DbType.AnsiStringFixedLength
  • Direction : Input
  • IsNullable : false
  • ParameterName : “@p1”
  • Precision : 0
  • Scale : 0
  • Size : 0
  • SqlDbType : Char
  • Value : “”

Then I select REC2 by using SSMS.
Then I copy the string contained in MY_SECOND_COL field.
Then I paste the string into Notepad++.
I notice the string is made up of 250 characters.
Why ?

Any help will be greatly appreciated

  • 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-06-11T09:02:23+00:00Added an answer on June 11, 2026 at 9:02 am
    SqlDbType : Char
    

    That’s your problem. You want VarChar. Chars are fixed width strings, padded with spaces.

    SqlDbType:

    Char String . A fixed-length stream of non-Unicode characters ranging between 1 and 8,000 characters.

    VarChar String . A variable-length stream of non-Unicode characters ranging between 1 and 8,000 characters. Use VarChar when the database column is varchar(max).

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

Sidebar

Related Questions

I'm developing an ASP .NET application, nothing fancy just another LOB App. Our company's
I'm working at a company that uses SCCS internally for developing it's main application.
i am developing an application for a real-estate company. the problem i am facing
I'm developing a new application for the company. The application have to exchange data
I'm currently developing an application that needs to store data in it's on database,
I am developing a internal .Net application in VS2010 for deployment within my company's
I'm developing an application for a client's website. Here's the story, this company uses
I am developing an application that uses Entity Framework and WPF with MVVM design
I am developing an application for a company, they gave me the admin role
At our company we are developing an application that will consists of several modules.

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.