Getting info from a sql server database when empty

  • Thread starter Thread starter Joesoft11a
  • Start date Start date
J

Joesoft11a

Guest
What I'm trying to do is load in a part of what I call is "bases". These relate to games. where users can add bases and then add missions from their games to that base. How ever the database is empty and I keep getting a "invalid object name : bases" bases is the name of the table where this table has 2 columns. I'm trying to load them in as I said the table is empty. My code is below. can some one tell me what I'm doing wrong. If the table is empty it should change a label to state that the table is empty and that there are no bases.


private void loadBases()
{

var uR = MLHSetting.Default.currGame;
SqlConnection conn = new SqlConnection();

conn.ConnectionString = @"Data Source=.\SQLEXPRESS; Initial Catalog=master;Trusted_Connection = true;";


conn.Open();
m_MapBases.Items.Clear();

try
{
string sql = "select * from bases "+ uR +" order by id asc";

SqlCommand command = new SqlCommand(sql, conn);
SqlDataReader reader = command.ExecuteReader();
//int count = 1;

if (reader.HasRows)
{
while (reader.Read())
{
object rowid = reader[0];

ListViewItem item = new ListViewItem(rowid.ToString());
item.SubItems.Add(reader["basename"].ToString());
item.SubItems.Add(reader["cname"].ToString());
//count++;
CurrGame.Text = uR;


}
}
else
{

m_MapBases.Items.Add("No Bases Available");
}
}
catch (Exception ee)
{
MessageBox.Show("Oops - " + ee.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
finally
{
conn.Close();
}
}








http://www.df-barracks.com Delta Force Barracks
http://www.starfiresoft.com Starfire Software

Continue reading...
 
Back
Top