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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:09:51+00:00 2026-05-16T17:09:51+00:00

I have a SQL Table with the following columns: PROFILE ———————————- Name | DateOfBirth

  • 0

I have a SQL Table with the following columns:

PROFILE
----------------------------------
Name | DateOfBirth | Address | ID
----------------------------------
     |             |         |
     |             |         |

[Name] is a required field while the ID is an autoincrement column.
The remaining fields are not required.

When it comes to displaying again the information of a user in my form, since the DateOfBirth field is not required I always got this value in my textBox 1900-01-01 00:00:00.000 even if it not supplied upon registration.

What I’m trying to accomplish is to display an empty string inthe textBox if the there’s no date of birth.

With my naive way of thinking, I wrote a method where it checks first the DateOfBirth column, if it is null, it will return an empty string, else, return the date of birth as a string ex. txtDateOfBirth.Text = GetDateOfBirth();
but it always return the value `1900-01-01 00:00:00.000′ cause the field in the database always inserts this value even the user leaves this field as blank.

Can you please help me… thanks…

I also tried this but still don’t work:

SELECT BIRTHDATE = CASE BIRTHDATE
            WHEN CAST('1900-01-01' AS DATETIME) THEN '' 
            ELSE BIRTHDATE END
FROM USER
  • 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-16T17:09:52+00:00Added an answer on May 16, 2026 at 5:09 pm

    I got it already! 🙂

    Here’s my original code:

    protected void SaveUser()
        {
            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
    
            SqlCommand cmd = new SqlCommand("INSERT_USER");
            cmd.Parameters.Add(new SqlParameter("@NAME", txtName.Text.Trim()));
            cmd.Parameters.Add(new SqlParameter("@ADDRESS", txtAddress.Text.Trim()));
            cmd.Parameters.Add(new SqlParameter("@DATEOFBIRTH", txtDateOfBirth.Text.Trim()));
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.ExecuteNonQuery();
        }
    

    In my original code, even though txtDateofBirth is empty, it will always pass an empty string to the parameter causing the database to insert ‘1900-01-01 00:00:00.00’, not the NULL value. Here’s the modified code. I check first if txtDateOfBirth is not empty (assuming the value entered is a valid date) if true, add cmd.Parameters.Add(new SqlParameter("@DATEOFBIRTH", txtDateOfBirth.Text.Trim())); as a parameter to INSERT_USER stored procedure. Else, @DATEOFBIRTH parameter is not being created and passed at all.

    protected void SaveUser()
    {
        SqlConnection conn = new SqlConnection(connectionString);
        conn.Open();
    
        SqlCommand cmd = new SqlCommand("INSERT_USER");
        cmd.Parameters.Add(new SqlParameter("@NAME", txtName.Text.Trim()));
        cmd.Parameters.Add(new SqlParameter("@ADDRESS", txtAddress.Text.Trim()));
        if(txtDateOfBirth.Text.Trim() != String.Empty)
            {
                cmd.Parameters.Add(new SqlParameter("@DATEOFBIRTH", txtDateOfBirth.Text.Trim()));
            }
        cmd.Connection = conn;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.ExecuteNonQuery();
    }
    

    SP:

    CREATE PROCEDURE [dbo].[INSERT_USER] 
    (
        @NAME AS VARCHAR(25),
        @ADDRESS AS VARCHAR(50) = NULL,
        @DATEOFBIRTH AS DATETIME = NULL
    )
    AS
    BEGIN
        INSERT INTO [USER] ([NAME], ADDRESS, DATEOFBIRTH) VALUES (@NAME, @ADDRESS, @DATEOFBIRTH)
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hierarchical (tree structure) SQL Server table TEmployee with following columns Id
I have a SQL table tablex with 3 columns(A, B ,C ). The following
I have a table with the following columns in SQL Server: MEMBERID, MEMBEREMAIL, FATHEREMAIL,
I have a SQL table (Trade Mapping) with the following columns: BTF_TRADE_MAPPING_KEY int BTF_SYSTEM_CODE
I have a T-SQL table that contains the following columns: Date, StationCode, HDepth, and
I'm using SQL-Server 2005 Standard. I have Users table with following columns: userID(int), userImage(varchar),
I have a table (SQL Server 2005) with the following columns: State: - StateId
In SQL Server 2005 I have a table with the following columns: Table Reservations:
In a SQL Server table I have the following 2 columns: RowId : primary
I have a (mysql) database table with the following columns: NAME | String (Unique)

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.