急送10分,求一段检查库中时候存在数据表的的.cs代码?解决思路

急送10分,求一段检查库中时候存在数据表的的.cs代码?要求:如果存在要查找的数据表返回一个值即可,如果没有

急送10分,求一段检查库中时候存在数据表的的.cs代码?
要求:如果存在要查找的数据表返回一个值即可,如果没有此该库则建立此库。

[解决办法]

C# code
        private bool ExistsTable(string TableName)        {            string sql = "select count(*) from sysobjects where name='" + TableName+"' and type='U'";            SqlConnection cn = new SqlConnection("連接字符串");            SqlCommand cmd = new SqlCommand(sql, cn);            try            {                cn.Open();                int cnt = Convert.ToInt32(cmd.ExecuteScalar());                return (cnt == 0) ? false : true;            }            finally            {                cn.Close();                cn.Dispose();                cmd.Dispose();            }        }
[解决办法]
C# code
            string sql = "create table tbname(col1 int primary key not null,col2 varchar(20) not null)";            SqlConnection cn = new SqlConnection("連接字符串");            SqlCommand cmd = new SqlCommand(sql, cn);            try            {                cn.Open();                cmd.ExecuteNonQuery();                //不出異常,就已經成功            }            finally            {                cn.Close();                cn.Dispose();                cmd.Dispose();                //失敗            }