How do I deal with this? I am getting an error for each get in the
Game class (see code below).
In the simplified example below I have reduced this to just 3 fields,
one which can be NULL. I have added 3 records to the table and ran the
program but it fails with the error above.
The application is supposed to create the hashtable of records as a
static feature which will be permanently available to my application.
To demonstrate that the HashTable is actually there I display the
contents in an ASP.NET page called Games.
When I run my application I get the error below:
= = = = = = = = = =
C:\Inetpub\wwwroot\ChatMark1\Game.cs(40):
'ChatMark1.Game.GameID.get': not all code paths return a value
= = = = = = = = = =
public class Global : System.Web.HttpApplication
{
public static string gameConnection = "packet size=4096;user
id=sa;pwd=monkey;data source=ASROCK;persist security
info=False;initial catalog=ChatMark1";
public static GameHashTable games;
private System.ComponentModel.IContainer components = null;
public Global()
{
InitializeComponent();
}
protected void Application_Start(Object sender, EventArgs e)
{
Global.GameLoad();
}
public static string GameConnection
{
get
{
return gameConnection;
}
}
public static void GameLoad()
{
SqlConnection connGames = new SqlConnection(gameConnection);
connGames.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Games",
connGames);
SqlDataReader reader;
reader = cmd.ExecuteReader();
Game game;
games = new GameHashTable();
while (reader.Read())
{
game = new Game((int)reader[0], (DateTime)reader[1],
(string)reader[2]);
games.Add(game);
}
connGames.Close();
}
public static GameHashTable Games
{
get
{
return games;
}
}
}
= = = = = = = = = =
// Games.aspx.cs.
public class Games : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgGames;
private void Page_Load(object sender, System.EventArgs e)
{
dgGames.DataSource = Global.Games;
dgGames.DataBind();
}
}
= = = = = = = = = =
public class GameHashTable : IEnumerable
{
Hashtable _games;
public GameHashTable()
{
// Contructor
_games = new Hashtable();
}
public IEnumerator GetEnumerator()
{
return _games.Values.GetEnumerator();
}
public Game this[int GameID]
{
get {return (Game) _games[GameID];}
set {Add(value);}
}
public void Add(Game Item)
{
if (Item == null)
throw new ArgumentException("Game can not be null");
_games.Add(Item.GameID, Item);
}
public void Remove(Game Item)
{
_games.Remove(Item.GameID);
}
}
= = = = = = = = = =
public class Game
{
private int _gameID;
private DateTime _playTime;
private string _image;
public Game(
int initialGameID,
DateTime initialPlayTime,
string initialImage )
{
GameID = initialGameID;
PlayTime = initialPlayTime;
Image = initialImage;
}
public int GameID
{
get {GameID = _gameID;}
set {_gameID = value;}
}
public DateTime PlayTime
{
get {PlayTime = _playTime;}
set {_playTime = value;}
}
public string Image
{
get {Image = _image;}
set {_image = value;}
}
}
= = = = = = = = = =
My Games Table in the ChatMark1 database.
CREATE TABLE Games (
gameID int IDENTITY (1, 1) NOT NULL ,
playTime datetime NOT NULL DEFAULT (getdate()),
image varchar (50) NULL ,
CONSTRAINT PK_Games PRIMARY KEY CLUSTERED (gameID) ON PRIMARY
) ON PRIMARY 3 8520
"Oberon" <Ob****@solstice.com> wrote in message
news:td********************************@4ax.com... How do I deal with this? I am getting an error for each get in the Game class (see code below).
In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I have added 3 records to the table and ran the program but it fails with the error above.
The application is supposed to create the hashtable of records as a static feature which will be permanently available to my application. To demonstrate that the HashTable is actually there I display the contents in an ASP.NET page called Games.
When I run my application I get the error below:
= = = = = = = = = = C:\Inetpub\wwwroot\ChatMark1\Game.cs(40): 'ChatMark1.Game.GameID.get': not all code paths return a value
= = = = = = = = = = public class Global : System.Web.HttpApplication {
public static string gameConnection = "packet size=4096;user id=sa;pwd=monkey;data source=ASROCK;persist security info=False;initial catalog=ChatMark1"; public static GameHashTable games; private System.ComponentModel.IContainer components = null;
public Global() { InitializeComponent(); }
protected void Application_Start(Object sender, EventArgs e) { Global.GameLoad(); }
public static string GameConnection { get { return gameConnection; } }
public static void GameLoad() { SqlConnection connGames = new SqlConnection(gameConnection); connGames.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM Games", connGames); SqlDataReader reader; reader = cmd.ExecuteReader();
Game game; games = new GameHashTable(); while (reader.Read()) { game = new Game((int)reader[0], (DateTime)reader[1], (string)reader[2]); games.Add(game); } connGames.Close(); }
public static GameHashTable Games { get { return games; } }
}
= = = = = = = = = = // Games.aspx.cs.
public class Games : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid dgGames;
private void Page_Load(object sender, System.EventArgs e) { dgGames.DataSource = Global.Games; dgGames.DataBind(); } } = = = = = = = = = = public class GameHashTable : IEnumerable { Hashtable _games;
public GameHashTable() { // Contructor _games = new Hashtable(); } public IEnumerator GetEnumerator() { return _games.Values.GetEnumerator(); } public Game this[int GameID] { get {return (Game) _games[GameID];} set {Add(value);} } public void Add(Game Item) { if (Item == null) throw new ArgumentException("Game can not be null"); _games.Add(Item.GameID, Item);
} public void Remove(Game Item) { _games.Remove(Item.GameID); } }
= = = = = = = = = =
public class Game { private int _gameID; private DateTime _playTime; private string _image;
public Game( int initialGameID, DateTime initialPlayTime, string initialImage ) { GameID = initialGameID; PlayTime = initialPlayTime; Image = initialImage; } public int GameID { get {GameID = _gameID;} set {_gameID = value;} } public DateTime PlayTime { get {PlayTime = _playTime;} set {_playTime = value;} } public string Image { get {Image = _image;} set {_image = value;} }
}
= = = = = = = = = =
My Games Table in the ChatMark1 database.
CREATE TABLE Games ( gameID int IDENTITY (1, 1) NOT NULL , playTime datetime NOT NULL DEFAULT (getdate()), image varchar (50) NULL , CONSTRAINT PK_Games PRIMARY KEY CLUSTERED (gameID) ON PRIMARY ) ON PRIMARY
The best place to start is exactly where it says the problem is:
C:\Inetpub\wwwroot\ChatMark1\Game.cs on line 40. Also, from within the IDE
you can double click on the error and it will take you there. However, the
bottom line is that you need to return a value from your get'ers, for
example:
public int GameID
{
get {return _gameID;}
set {_gameID = value;}
}
"Oberon" <Ob****@solstice.com> a écrit dans le message de news: td********************************@4ax.com... How do I deal with this? I am getting an error for each get in the Game class (see code below).
public class Game { private int _gameID; private DateTime _playTime; private string _image;
public Game( int initialGameID, DateTime initialPlayTime, string initialImage ) { GameID = initialGameID; PlayTime = initialPlayTime; Image = initialImage; } public int GameID { get {GameID = _gameID;} set {_gameID = value;} } public DateTime PlayTime { get {PlayTime = _playTime;} set {_playTime = value;} } public string Image { get {Image = _image;} set {_image = value;} }
}
You have declared you properties incorrectly; for some reason you ar trying
to set the property in the getter !!!
public int GameID
{
get {return _gameID;}
set {_gameID = value;}
}
public DateTime PlayTime
{
get {return _playTime;}
set {_playTime = value;}
}
public string Image
{
get {return _image;}
set {_image = value;}
}
Joanna
--
Joanna Carter
Consultant Software Engineer
Oh dear,
That's just the kind of error beginners make isn't it?
public int GameID
{
get {GameID = _gameID;}
set {_gameID = value;}
}
In my mind I thought that 'GameID = _gameID' would set the property to
the value of the hidden field. Silly me.
Thanks.
On Thu, 19 May 2005 07:18:42 -0400, "Andy Walldorff"
<an************@daytonrcs.REMOVE.com> wrote: "Oberon" <Ob****@solstice.com> wrote in message news:td********************************@4ax.com.. . How do I deal with this? I am getting an error for each get in the Game class (see code below).
In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I have added 3 records to the table and ran the program but it fails with the error above.
The application is supposed to create the hashtable of records as a static feature which will be permanently available to my application. To demonstrate that the HashTable is actually there I display the contents in an ASP.NET page called Games.
When I run my application I get the error below:
= = = = = = = = = = C:\Inetpub\wwwroot\ChatMark1\Game.cs(40): 'ChatMark1.Game.GameID.get': not all code paths return a value
= = = = = = = = = = public class Global : System.Web.HttpApplication {
public static string gameConnection = "packet size=4096;user id=sa;pwd=monkey;data source=ASROCK;persist security info=False;initial catalog=ChatMark1"; public static GameHashTable games; private System.ComponentModel.IContainer components = null;
public Global() { InitializeComponent(); }
protected void Application_Start(Object sender, EventArgs e) { Global.GameLoad(); }
public static string GameConnection { get { return gameConnection; } }
public static void GameLoad() { SqlConnection connGames = new SqlConnection(gameConnection); connGames.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM Games", connGames); SqlDataReader reader; reader = cmd.ExecuteReader();
Game game; games = new GameHashTable(); while (reader.Read()) { game = new Game((int)reader[0], (DateTime)reader[1], (string)reader[2]); games.Add(game); } connGames.Close(); }
public static GameHashTable Games { get { return games; } }
}
= = = = = = = = = = // Games.aspx.cs.
public class Games : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid dgGames;
private void Page_Load(object sender, System.EventArgs e) { dgGames.DataSource = Global.Games; dgGames.DataBind(); } } = = = = = = = = = = public class GameHashTable : IEnumerable { Hashtable _games;
public GameHashTable() { // Contructor _games = new Hashtable(); } public IEnumerator GetEnumerator() { return _games.Values.GetEnumerator(); } public Game this[int GameID] { get {return (Game) _games[GameID];} set {Add(value);} } public void Add(Game Item) { if (Item == null) throw new ArgumentException("Game can not be null"); _games.Add(Item.GameID, Item);
} public void Remove(Game Item) { _games.Remove(Item.GameID); } }
= = = = = = = = = =
public class Game { private int _gameID; private DateTime _playTime; private string _image;
public Game( int initialGameID, DateTime initialPlayTime, string initialImage ) { GameID = initialGameID; PlayTime = initialPlayTime; Image = initialImage; } public int GameID { get {GameID = _gameID;} set {_gameID = value;} } public DateTime PlayTime { get {PlayTime = _playTime;} set {_playTime = value;} } public string Image { get {Image = _image;} set {_image = value;} }
}
= = = = = = = = = =
My Games Table in the ChatMark1 database.
CREATE TABLE Games ( gameID int IDENTITY (1, 1) NOT NULL , playTime datetime NOT NULL DEFAULT (getdate()), image varchar (50) NULL , CONSTRAINT PK_Games PRIMARY KEY CLUSTERED (gameID) ON PRIMARY ) ON PRIMARY
The best place to start is exactly where it says the problem is: C:\Inetpub\wwwroot\ChatMark1\Game.cs on line 40. Also, from within the IDE you can double click on the error and it will take you there. However, the bottom line is that you need to return a value from your get'ers, for example:
public int GameID { get {return _gameID;} set {_gameID = value;} } This discussion thread is closed Replies have been disabled for this discussion. Similar topics
1 post
views
Thread by Wayno |
last post: by
|
5 posts
views
Thread by Tony Wright |
last post: by
|
6 posts
views
Thread by Peter Afonin |
last post: by
|
12 posts
views
Thread by Jose Fernandez |
last post: by
|
4 posts
views
Thread by OutdoorGuy |
last post: by
|
7 posts
views
Thread by p |
last post: by
| | | | | | | | | | | | | |