Hashtable takes only two argument in Add method whereas you are passing 10 arguments, a typical Add method of hashtable is below:
Hashtable hs = new Hashtable();
//to add a value
hs.Add("name", "John Carter");
//to retrieve the value
string name = hs["name"].ToString();
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
yes in every loop the values will get changed, so at the end you'll have only one collection of Player.
I would suggest to create a player class and use List<yourPlayerclass> to add the values in the collection, if you'll do this, you will be able to see the collection of Players in your case.
you can implement it further with the code help:
your class could be:
class Player
{
public string playerId { get; set; }
public string Name { get; set; }
public bool isNotOut { get; set; }
public int NumberRuns { get; set; }
public int teamId { get; set; }
}
Your code should be:
List<Player> objPlayer = new List<Player>();
foreach (XmlNode nodes in xmlBats)
{
string pID = nodes.Attributes["playerId"].Value;
string playerName = nodes.SelectSingleNode("Name").InnerText;
Boolean IsNotOut = Convert.ToBoolean(nodes.Attributes["isNotOut"].Value);
int numberRuns = Convert.ToInt32(nodes.SelectSingleNode("Run").InnerText);
int teamId = Convert.ToInt32(node.Attributes["teamId"].Value);
Player clsPlayer = new Player();
clsPlayer.isNotOut = IsNotOut;
clsPlayer.playerId = pID;
clsPlayer.Name = playerName;
clsPlayer.NumberRuns = numberRuns;
clsPlayer.teamId = teamId;
objPlayer.Add(clsPlayer);
}
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
Since you are working with multiple player objects, you can not do the above. See my solution. You have to use class for the player. Each time construct a new object for each player and store in hashtable.
Please Mark As Answer if it helped.
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
luke_bryant
Member
396 Points
363 Posts
Hash tables
Apr 02, 2012 10:33 AM|LINK
Hi Programmers,
I am trying to add items to a hash table and I get the following error Error 1 No overload for method 'Add' takes 10 arguments .
Below is my c# code:
Hashtable playerHsh = new Hashtable(); playerHsh.Add("playerid",pID, "PlayerName",playerName,"IsNotOut",IsNotOut,"NumberRuns",numberRuns,"TeamID",teamId);luke_bryant
Member
396 Points
363 Posts
Re: Hash tables
Apr 02, 2012 10:40 AM|LINK
I wanna have the playerid as the key and the key contains the values above but I am new to hash tables so dont know how to do this
kedarrkulkar...
All-Star
35573 Points
5700 Posts
Re: Hash tables
Apr 02, 2012 10:42 AM|LINK
hastable stores key-value pair
you can have only two parameters in Add method of hastable
http://msdn.microsoft.com/en-us/library/system.collections.hashtable.add.aspx
u seem to try adding multiple items in hashtable.... u should do like this
playerHsh.Add("playerid",pID); playerHsh.Add("PlayerName",playerName); playerHsh.Add("IsNotOut",IsNotOut); playerHsh.Add("NumberRuns",numberRuns); playerHsh.Add("TeamID",teamId);hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: Hash tables
Apr 02, 2012 10:42 AM|LINK
Hashtable takes only two argument in Add method whereas you are passing 10 arguments, a typical Add method of hashtable is below:
Hashtable hs = new Hashtable(); //to add a value hs.Add("name", "John Carter"); //to retrieve the value string name = hs["name"].ToString();Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
shivalthakur
Participant
1863 Points
542 Posts
Re: Hash tables
Apr 02, 2012 10:43 AM|LINK
it shoul be something like that
Response.Write("Success");
Best Of Luck
Shival Thakur
adeelehsan
All-Star
18597 Points
2791 Posts
Re: Hash tables
Apr 02, 2012 10:44 AM|LINK
You should crearte a separate class for player like:
class Player { int pID, string playerName, bool IsNotOut, int numberRuns, int teamId }Then in the hashtable do the following:
Later you can always access a full plater object using the pID as key.
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
luke_bryant
Member
396 Points
363 Posts
Re: Hash tables
Apr 02, 2012 10:48 AM|LINK
Thanks for the help. My code is below so what would happen to the hash within this code will the key change?
foreach (XmlNode nodes in xmlBats) { string pID = nodes.Attributes["playerId"].Value; string playerName = nodes.SelectSingleNode("Name").InnerText; Boolean IsNotOut = Convert.ToBoolean(nodes.Attributes["isNotOut"].Value); int numberRuns = Convert.ToInt32(nodes.SelectSingleNode("Run").InnerText); int teamId = Convert.ToInt32(node.Attributes["teamId"].Value); playerHsh.Add("playerid", pID); playerHsh.Add("PlayerName", playerName); playerHsh.Add("IsNotOut",IsNotOut); playerHsh.Add("NumberRuns",numberRuns); playerHsh.Add("TeamID",teamId); }luke_bryant
Member
396 Points
363 Posts
Re: Hash tables
Apr 02, 2012 10:50 AM|LINK
How would I implement this when the number of players could change?
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: Hash tables
Apr 02, 2012 10:51 AM|LINK
yes in every loop the values will get changed, so at the end you'll have only one collection of Player.
I would suggest to create a player class and use List<yourPlayerclass> to add the values in the collection, if you'll do this, you will be able to see the collection of Players in your case.
you can implement it further with the code help:
your class could be:
class Player { public string playerId { get; set; } public string Name { get; set; } public bool isNotOut { get; set; } public int NumberRuns { get; set; } public int teamId { get; set; } }Your code should be:
List<Player> objPlayer = new List<Player>(); foreach (XmlNode nodes in xmlBats) { string pID = nodes.Attributes["playerId"].Value; string playerName = nodes.SelectSingleNode("Name").InnerText; Boolean IsNotOut = Convert.ToBoolean(nodes.Attributes["isNotOut"].Value); int numberRuns = Convert.ToInt32(nodes.SelectSingleNode("Run").InnerText); int teamId = Convert.ToInt32(node.Attributes["teamId"].Value); Player clsPlayer = new Player(); clsPlayer.isNotOut = IsNotOut; clsPlayer.playerId = pID; clsPlayer.Name = playerName; clsPlayer.NumberRuns = numberRuns; clsPlayer.teamId = teamId; objPlayer.Add(clsPlayer); }Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
adeelehsan
All-Star
18597 Points
2791 Posts
Re: Hash tables
Apr 02, 2012 10:52 AM|LINK
Since you are working with multiple player objects, you can not do the above. See my solution. You have to use class for the player. Each time construct a new object for each player and store in hashtable.
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011