charlestonlaw
asked on
Insert &nbsp or " " instead of DbNull when field left blank in gridview?
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(ob ject 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
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(ob
{
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there any way to use the + in SQL Server 2005? I'm getting an error with them.
ASKER
This is the error:
Error in list of function arguments: '+' not recognized.
Unable to parse query text.
Error in list of function arguments: '+' not recognized.
Unable to parse query text.
ASKER
Okay it's late... I know the + works just wondering why your query is giving me an error Chirag...
Thanks!
Thanks!
ASKER
SELECT aircraftID, aircraftManu + ' ' + ISNULL(aircraftName, ' ') + ' ' + aircraftNumber AS aName FROM aircraft ORDER BY aName
the code above works..
Thanks!
the code above works..
Thanks!
it is CHIRAG query:
SELECT 'aircraftID', 'aircraftManu' + IsNUll('aircraftName',' ') as aircraftName , 'aircraftNumber' AS aName --FROM aircraft ORDER BY aName
must replaced + with ,
probebly chirag right it fast if not actually he found this
SELECT 'aircraftID', 'aircraftManu' + IsNUll('aircraftName',' ') as aircraftName , 'aircraftNumber' AS aName --FROM aircraft ORDER BY aName
must replaced + with ,
probebly chirag right it fast if not actually he found this
------
SELECT aircraftID, aircraftManu + ' ' + aircraftName + ' ' + aircraftNumber AS aName FROM aircraft ORDER BY aName
where aircraftName is not null
union
SELECT aircraftID, aircraftManu + ' ' + aircraftNumber AS aName FROM aircraft ORDER BY aName
where artifactName is null
------