public string getTypenameById(int TypeId)
{
try
{
string sql = "select TypeName from RoomType where TypeId='" + TypeId + "'";
SqlCommand scm = new SqlCommand(sql, con.getCon());
con.getCon().Open();
SqlDataReader sdr = scm.ExecuteReader(); string typename = string.Empty;
while (sdr.Read())
{
typename = (string)sdr["RoomType"];
}
return typename;
sdr.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally {
con.getCon().Close();
}
}
{
try
{
string sql = "select TypeName from RoomType where TypeId='" + TypeId + "'";
SqlCommand scm = new SqlCommand(sql, con.getCon());
con.getCon().Open();
SqlDataReader sdr = scm.ExecuteReader(); string typename = string.Empty;
while (sdr.Read())
{
typename = (string)sdr["RoomType"];
}
return typename;
sdr.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally {
con.getCon().Close();
}
}
这句
{
public SqlConnection getCon()
{
string connectionstring = "server=.;trusted_connection=true;database=HotelManage";
SqlConnection con = new SqlConnection(connectionstring);
return con; }
}
在程序上又new了一遍
sqlconnection 好了