O
Oberon
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
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