ObjectDataSource - Select - Nullable parameter

R

rbrowning1958

Hello,

Have an objectdatasource with a method much like this:

public SomeDataSet.MyDataTable getMyDataTable(int? pkID)
{
if (pkID == null)
return adapater.GetMyTable("ALL")
else
return adapter.GetMyTable("SING")
}

When I configure the objectdatasource I tell it to call this method
for the select. In the define parameters if I give it a value of 1, or
2, or some other integer works fine. If I tell it to use null as the
default value, at run time I get an error "Input string was not in
correct format". Any ideas anyone?

Thanks

Ray
 
R

rbrowning1958

Hello,

Have an objectdatasource with a method much like this:

public SomeDataSet.MyDataTable getMyDataTable(int? pkID)
{
  if (pkID == null)
     return adapater.GetMyTable("ALL")
  else
     return adapter.GetMyTable("SING")

}

When I configure the objectdatasource I tell it to call this method
for the select. In the define parameters if I give it a value of 1, or
2, or some other integer works fine. If I tell it to use null as the
default value, at run time I get an error "Input string was not in
correct format". Any ideas anyone?

Thanks

Ray

For anyone interested I solved this. You just leave the parameter
empty - don't try typing in null doh!

Ray
 
L

Lloyd Sheen

rbrowning1958 said:
Hello,

Have an objectdatasource with a method much like this:

public SomeDataSet.MyDataTable getMyDataTable(int? pkID)
{
if (pkID == null)
return adapater.GetMyTable("ALL")
else
return adapter.GetMyTable("SING")
}

When I configure the objectdatasource I tell it to call this method
for the select. In the define parameters if I give it a value of 1, or
2, or some other integer works fine. If I tell it to use null as the
default value, at run time I get an error "Input string was not in
correct format". Any ideas anyone?

Thanks

Ray

If I may make a suggestion. Create an enum with each value for GetMyTable
and then use a switch statement to do the correct GetMyTable. In case you
have to get another table this would be much more flexable and
understandable later.

LS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top