asp.net 在登录界面上判断是否存在数据库DB_Happy,急 急 急
asp。net在登录界面上判断是否存在数据库DB_Happy 如果有的话就不用再附加了, 如果没有则附加一个数据库DB_Happy
请大家把代码写的详细一点,如果有用马上给分! 谢谢了
[解决办法]
string str = "select name from sysdatabases WHERE name='RfIDMeeting'";
SqlCommand myCommand = new SqlCommand(str, myConn);
string haha = Convert.ToString(myCommand.ExecuteScalar());
if (haha != "RfIDMeeting") //不存在数据库
{
//str = "IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'" + DbName + "')" + "beginEXEC sp_detach_db " + DbName + " end " + "EXEC sp_attach_db @dbname ='MarryHappy',@filename1=N'" + strMdf + "',@filename2=N'" + strLdf + "'";
str = "EXEC sp_attach_db @dbname ='RfIDMeeting',@filename1=N'" + strMdf + "',@filename2=N'" + strLdf + "'";
myCommand = new SqlCommand(str, myConn);
myCommand.ExecuteNonQuery();
}
照这种方式改你要的代码就可以了