We help IT Professionals succeed at work.
Get Started

Insert &nbsp or " " instead of DbNull when field left blank in gridview?

charlestonlaw
on
1,204 Views
Last Modified: 2010-10-05
I have a Gridview that does updating and when I leave a field blank it inserts a null value into the database instead of "".  In my case the airline name is optional so if the user leaves it blank i want it to insert "" instead of sql server showing <i>null</i>.

I've been playing around but this is only as far as I have gotten... I think I'm heading in the right direction, any ideas?

protected void grdAircraft_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        foreach (DictionaryEntry entry in e.NewValues)
        {
            //if (e.NewValues[entry.Value] == null) { e.NewValues[entry.Value] = ""; }
        }
    }

----- OR -----

Could I change my SQL query so it could work with nulls?

SELECT aircraftID, aircraftManu + ' ' + aircraftName + ' ' + aircraftNumber AS aName FROM aircraft ORDER BY aName
I'm binding a dropdownlist to this query but when aircraftName(which is the field I don't want null) is null, all rows with that null value don't show up in my results.  Could I change the SQL query to have it show up or do I need go attack it with the method above so I can get this to work?

Thanks
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE