shuchi

shuchi

  • NA
  • 10
  • 0

how to insert null value(if present) from database into DDL of DataGrid?

Dec 4 2006 10:33 AM
I am using C#.NET, Visual Web Develpoper, SQL Server 2000.

In my WebForm, I am trying to get the value from database using following code : Where OSP_OrderNum is the column name in database.

// Get the value of the OSP_OrderNum field.

ordernum = (string)DataBinder.Eval(e.Item.DataItem, "OSP_OrderNum");

Here I am trying to insert the value of OSP_OrderNum into a dropdownlist of a DataGrid. Now what I would like to do is

if (ordernum == " ")

{

insert Text : "**Select Order**" into DDL

}

else

{

insert : "**Select 'ordernum**' order"

}

When I am using this loop my code breaks on the 1st line itself where I have declared ordernum. It is not able to capture null value from the database and giving me error: Unable to cast object of type 'System.DBNull' to type 'System.String'

How do I Solve this ?

Please Help!!!!




Answers (1)