Conversion Problem

  • Thread starter Thread starter Roger
  • Start date Start date
R

Roger

Hi all

I have posted in .net cf but not had any joy

Maybe you can help



I have been trying to adapt the code on this page
http://support.microsoft.com/kb/310143 to work on windows mobile 5.
web application fine of course.

Load event i have changed to this

localhost.Service1 MyService = new localhost.Service1();
dataGrid1.DataSource = MyService.GetCustomers().Tables
["client"];
that work fine loads the data grid.

I have work out how to change the data in the datagrid

Problem comes when saving it back to the service

localhost.Service1 MyService = new localhost.Service1();
EXCEPTION ERROR at this line DataSet ds =
(DataSet)dataGrid1.DataSource;
DataSet
dsChanges = ds.GetChanges();
if
(dsChanges != null)
{
ds.Merge(MyService.UpdateCustomers(dsChanges),
true);
}

I think it has somthing to do with the databinding but after a couple of
evenings I now dont know where to look
any help would be apprecitated.

Thanks in advance

Roger
 
Roger,

Well, you are setting the DataSource property to a DataTable, and trying
to cast it to a DataSet on the way out. You should be getting an
InvalidCastException here.
 
To debug , do this:

DataSet ds =
(DataSet)dataGrid1.DataSource;


object o tempObject = dataGrid1.DataSource;
if (null!= tempObject)
{
Console.Writeline ( tempObject.ToString());
}

Put a debug line on it. When it stops there, check the Watch Window. It'll
show the object type. (This is one of several ways to see this).

But as Mark points out, you've got an object mismatch.

Once you figure it out, get rid of the tempObject code above.




Roger said:
Hi all

I have posted in .net cf but not had any joy

Maybe you can help



I have been trying to adapt the code on this page
http://support.microsoft.com/kb/310143 to work on windows mobile 5.
web application fine of course.

Load event i have changed to this

localhost.Service1 MyService = new localhost.Service1();
dataGrid1.DataSource = MyService.GetCustomers().Tables
["client"];
that work fine loads the data grid.

I have work out how to change the data in the datagrid

Problem comes when saving it back to the service

localhost.Service1 MyService = new localhost.Service1();
EXCEPTION ERROR at this line DataSet ds =
(DataSet)dataGrid1.DataSource;
DataSet
dsChanges = ds.GetChanges();
if
(dsChanges != null)
{
ds.Merge(MyService.UpdateCustomers(dsChanges),
true);
}

I think it has somthing to do with the databinding but after a couple of
evenings I now dont know where to look
any help would be apprecitated.

Thanks in advance

Roger
 
Who's Mark? =)


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

sloan said:
To debug , do this:

DataSet ds =
(DataSet)dataGrid1.DataSource;


object o tempObject = dataGrid1.DataSource;
if (null!= tempObject)
{
Console.Writeline ( tempObject.ToString());
}

Put a debug line on it. When it stops there, check the Watch Window.
It'll
show the object type. (This is one of several ways to see this).

But as Mark points out, you've got an object mismatch.

Once you figure it out, get rid of the tempObject code above.




Roger said:
Hi all

I have posted in .net cf but not had any joy

Maybe you can help



I have been trying to adapt the code on this page
http://support.microsoft.com/kb/310143 to work on windows mobile 5.
web application fine of course.

Load event i have changed to this

localhost.Service1 MyService = new localhost.Service1();
dataGrid1.DataSource = MyService.GetCustomers().Tables
["client"];
that work fine loads the data grid.

I have work out how to change the data in the datagrid

Problem comes when saving it back to the service

localhost.Service1 MyService = new localhost.Service1();
EXCEPTION ERROR at this line DataSet ds =
(DataSet)dataGrid1.DataSource;
DataSet
dsChanges = ds.GetChanges();
if
(dsChanges != null)
{
ds.Merge(MyService.UpdateCustomers(dsChanges),
true);
}

I think it has somthing to do with the databinding but after a couple of
evenings I now dont know where to look
any help would be apprecitated.

Thanks in advance

Roger
 
Ok just got home from work and not digested this I guess
But why does it work in windows app and not cf

Any way I will look as you have suggested

Thanks for the replys
 
Good question.


I must have had 2 posts up at once or something.


I'm doing brain-dead work right now, thus my active-ness on the forums.






Nicholas Paldino said:
Who's Mark? =)


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

sloan said:
To debug , do this:

DataSet ds =
(DataSet)dataGrid1.DataSource;


object o tempObject = dataGrid1.DataSource;
if (null!= tempObject)
{
Console.Writeline ( tempObject.ToString());
}

Put a debug line on it. When it stops there, check the Watch Window.
It'll
show the object type. (This is one of several ways to see this).

But as Mark points out, you've got an object mismatch.

Once you figure it out, get rid of the tempObject code above.




Roger said:
Hi all

I have posted in .net cf but not had any joy

Maybe you can help



I have been trying to adapt the code on this page
http://support.microsoft.com/kb/310143 to work on windows mobile 5.
web application fine of course.

Load event i have changed to this

localhost.Service1 MyService = new localhost.Service1();
dataGrid1.DataSource = MyService.GetCustomers().Tables
["client"];
that work fine loads the data grid.

I have work out how to change the data in the datagrid

Problem comes when saving it back to the service

localhost.Service1 MyService = new localhost.Service1();
EXCEPTION ERROR at this line DataSet ds =
(DataSet)dataGrid1.DataSource;
DataSet
dsChanges = ds.GetChanges();
if
(dsChanges != null)
{
ds.Merge(MyService.UpdateCustomers(dsChanges),
true);
}

I think it has somthing to do with the databinding but after a couple of
evenings I now dont know where to look
any help would be apprecitated.

Thanks in advance

Roger
 
no Problem

I do know this !

DataGrid does not support databinding inn CF

Sorry about the typ of post but i cannot reply !
 
Back
Top