IT Community - Software Programming, Web Development and Technical Support

Cannot implicitly convert type 'void' to 'System.Data.DataTable'

This is a discussion on Cannot implicitly convert type 'void' to 'System.Data.DataTable' within the C# Programming forums, part of the Software Development category; Cannot implicitly convert type 'void' to 'System.Data.DataTable' private static void FromDictionary(SqlDataReader dr) { string eText = string.Empty; DataTable ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-30-2007, 09:51 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Cannot implicitly convert type 'void' to 'System.Data.DataTable'

Cannot implicitly convert type 'void' to 'System.Data.DataTable'


private static void FromDictionary(SqlDataReader dr)
{
string eText = string.Empty;
DataTable dictionaryWords = new DataTable();
DataTable dt = new DataTable();
dt = dt.Load(dr);
if (dr != null)
{
dictionaryWords = dt; <<<<<<<<<< ERROR: Cannot implicitly convert type 'void' to 'System.Data.DataTable'
}
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 09:57 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Cannot implicitly convert type 'void' to 'System.Data.DataTable'

You probably are returning the datatable. If thats the case, make your function declaration to return a datatable.

private static DataTable FromDictionary(SqlDataReader dr)
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-30-2007, 09:57 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Cannot implicitly convert type 'void' to 'System.Data.DataTable'

I would say this line 5 is actually stuff up:

dt = dt.Load(dr); // <-- as Load() function is type of void

All you need to do is just load with datareader and do no need to assign it back to your dt

e.g.

dt.load(dr);
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-30-2007, 09:59 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Cannot implicitly convert type 'void' to 'System.Data.DataTable'

I change the code to return DataTable but still same error:


private static DataTable FromDictionary(SqlDataReader dr)
{
DataTable dictionaryWords = new DataTable();
DataTable dt = new DataTable();

if (dr != null)
{
dictionaryWords = dt.Load(dr); <<<<<<<<<error
}


Its all about coding!
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-30-2007, 10:01 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Cannot implicitly convert type 'void' to 'System.Data.DataTable'

First of all, are you even returning a datatable from your method?
Also, refer to my previous replies about Load method.
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-30-2007, 10:02 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Cannot implicitly convert type 'void' to 'System.Data.DataTable'

can you modify my code please? i'm still getting error
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-30-2007, 10:06 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Cannot implicitly convert type 'void' to 'System.Data.DataTable'

you run into the conversion problem because Load return void. May be this help you.


DataTable dictionaryWords = new DataTable();DataTable dt = new DataTable();

dt.Load(dr);


if (dr != null)

{

dictionaryWords = dt;

}

return dt;
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-30-2007, 10:08 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Thumbs up Re: Cannot implicitly convert type 'void' to 'System.Data.DataTable'

hi.....


I got it.... what u said.....


thanks.... it works fine..... great
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Dataview to Datatable it.wily C# Programming 2 01-23-2008 02:51 AM
What is the difference between "using System.Data;" and directly adding the refer KiruthikaSambandam ASP and ASP.NET Programming 1 11-15-2007 01:33 AM
Anybody explain about "Common Type System" (CTS)? H2o ASP and ASP.NET Programming 5 08-09-2007 08:02 AM
void return type anbuchezhians Java Programming 1 07-25-2007 05:55 AM
Convert integer type variable to char array oyu2o C and C++ Programming 0 03-10-2007 09:47 AM


All times are GMT -7. The time now is 08:58 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0