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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:53:48+00:00 2026-06-07T03:53:48+00:00

I am rewriting this long INSERT statement and parameters used to look like this:

  • 0

I am rewriting this long INSERT statement and parameters used to look like this:

    cmd.Parameters.AddWithValue("@Website", General.fnSQLNullValues(tWebsite.Text))

Where General.fnSQLNullValues is this:

        Public Shared Function fnSQLNullValues(ByVal sValue As Object, Optional ByVal Len As Integer = 999999) As Object
            If sValue Is Nothing Then Return DBNull.Value
            fnSQLNullValues = IIf(sValue.ToString.Length = 0, DBNull.Value, Left(sValue.ToString(), Len))
        End Function

I don’t like this at all , and it seems to be alot of code all to do just this,

       cmd.Parameters.AddWithValue("@Website" , If(tWebsite.Text , DBNull.Value))

from my understanding , that one line of code there DBNull.Value will replace tWebsite.Text as the value if tWebsite.Text is null or not accepted and it seems to me to do the same thing as the other function in General. Is this correct and is one way any better then the other?

Also , I get Warning : “Cannot Infer Common Type; Object Assumed” from the second way , but it seems to me that the first way was using a generic object anyways , so I do not know if I should just ignore this warning

  • 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-07T03:53:49+00:00Added an answer on June 7, 2026 at 3:53 am

    Strings are a little tricky when working with database parameters in code. If you have an empty string, it will pass an empty string value for insertion. However, if you set you set your string to a value of Nothing, it will insert a NULL value into the database. Otherwise it will set an empty string.

    Ideally, you’d have some kind of business layer on top of your data layer that will check your tWebsite.Text value and either pass in Nothing or the Text value to your function that sets up the parameters. This is slightly different that your first code example above. That way your data layer only has to execute the following command:

    cmd.Parameters.AddWithValue("@Website" , valueWebsite))
    

    …and no hassle is necessary.

    For other data types (such as integers, decimals, etc.), check out the Nullable Types and work with them. They make things really easy to work with. By default they initialize to Nothing, so if you don’t assign it a value (from your input boxes) the value stays Nothing and will do a proper NULL insert into the database.

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

Sidebar

Related Questions

I'm rewriting an LOB application whose architecture is like this: Silverlight && Windows Mobile
I'm rewriting a url to a users profile with mod_rewrite like this: domain.com/users/JohnSmith. I
I have a method in a url rewriting module that looks like this public
This question is about rewriting git history. Six months ago I decided to make
i'm using this rule for rewriting subdomain and i'm corrected host file to 127.0.0.1
I know this question is overly popular, but I find nothing that addresses rewriting
Edit: I'm rewriting this question because I apparently wasn't clear. Sometimes the GPS service
This should be an easy one, looks like I got myself too confused. I
First up, i realize this application has some design issues and while rewriting a
From a long time i am struggling for with this program. I am having

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.