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.
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?
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
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?
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
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.
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?
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.
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
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.