|
-
April 13th, 2012, 08:55 PM
#1
Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
Code:
Command cmd = e.Command;
switch (cmd.CommandType)
{
case CommandType.Login:
{
string name = SetManagerName(cmd.SenderIP, cmd.MetaData);
if (!IsNameExists(cmd.SenderIP, name))
{
SendUserOnlineList();
}
else
{
Command sendcmd = new Command(CommandType.NameExists, cmd.SenderIP);
sendcmd.SenderIP = serverIp;
sendcmd.SenderName = "server";
client.SendCommand(sendcmd);
}
break;
}
I'm writing this code, but I got the error: Error 2 Argument 1: cannot convert from 'Command.CommandType' to 'System.Data.CommandType' D:\Laptrinh\topup\System Programming\Nha\UITChatServer\Server\ClientManager.cs 120 47 Server
Please give me any advice about this error? Thanks for any help.
-
April 13th, 2012, 09:40 PM
#2
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
On what line does this error occur?
Also, what is CommandType? Is this a built-in enum, or was it implemented by you? What about Command?
Last edited by Talikag; April 13th, 2012 at 09:42 PM.
-
April 13th, 2012, 09:43 PM
#3
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
sorry, I forgot this. The below line appear the error:
Code:
case CommandType.Login:
Thanks
-
April 13th, 2012, 09:49 PM
#4
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
What is CommandType? Is this a built-in enum, or was it implemented by you?
Also, what is the type of Command.CommandType?
-
April 13th, 2012, 09:55 PM
#5
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
Code:
public class Command
{
private IPAddress senderIP;
public IPAddress SenderIP
{
get { return senderIP; }
set { senderIP = value; }
}
private CommandType cmdType;
public CommandType CommandType
{
get { return cmdType; }
set { cmdType = value; }
}
private string commandBody;
public string MetaData
{
get { return commandBody; }
set { commandBody = value; }
}
// 2 contructor
public Command(CommandType type, IPAddress targetMachine, string metaData)
{
this.cmdType = type;
this.target = targetMachine;
this.commandBody = metaData;
}
public Command(CommandType type, IPAddress targetMachine)
{
this.cmdType = type;
this.target = targetMachine;
this.commandBody = "";
}
}
This is the code i wrote in the my class: Command.cs.
Thanks for any help
-
April 13th, 2012, 10:03 PM
#6
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
Where is the definition of CommandType?
The error probably occurs because when you write
Code:
private CommandType cmdType;
It is actually equivalent to
Code:
private System.Data.CommandType cmdType;
(System.Data.CommandType is some built-in enum)
If I'm right, this can be solved by replacing the above line with
Code:
private YOUR_SOLUTION_NAME.CommandType cmdType;
You should do the same wherever you use the "CommandType" type.
-
April 14th, 2012, 12:55 AM
#7
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
Thanks for your help Talikag, but could you elaborate your answer, what do you mean? Will I change the my class' name to another name?
-
April 14th, 2012, 11:14 AM
#8
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
Changing the name of CommandType is also an option.
However, what I meant is that you need to replace the following two lines
Code:
private CommandType cmdType;
public CommandType CommandType
{
get { ... }
set { ... }
}
With:
Code:
private YOUR_SOlUTION_NAME.CommandType cmdType;
public YOUR_SOlUTION_NAME.CommandType CommandType
{
get { ... }
set { ... }
}
where YOUR_SOlUTION_NAME is the name of the solution shown in the top of the Solution Explorer.
-
April 15th, 2012, 09:08 AM
#9
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
Thanks for your help, Talikag
I did as you said, but it didn't run, another error happen: the type or namespace name could not be found. I will try to change class name.
Thanks again
-
April 16th, 2012, 02:15 AM
#10
Re: Error:cannot convert 'Command.CommandType' to'System.Data.CommandType'
Is your intellisense functionality disabled ? I suppose it will hint what you may need to choose and change once your mouse cursor is over the text item in question.
In general, changing variable's name to get one's current code snip done in the first place works with local small projects, what if one has larger projects of code and the source is huge in size ? Mismatch object names propagating throughout the code-base would burden and frustrate coders and testers significantly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|