1
1楼 yuanyuyuyu 2007-01-16 16:31:14 SqlConnection conn = new SqlConnection( "Data Source=(local);initial catalog=master;user id=sa;pwd= "); SqlCommand command = new SqlCommand( "create database ' " + DataBaseName + " ' ", conn); try { conn.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conn.Close(); } 总是报错!可能command.ExecuteNonQuery();的原因 2楼 TheRule 2007-01-16 16:33:43 public bool CreatDatabase(string DatabaseName,string DataFile,string LogFile) { string str; SqlConnection myConn = new SqlConnection ( "Server=localhost;Integrated security=SSPI;database=master "); str = "CREATE DATABASE "+ DatabaseName + " ON PRIMARY " + "(NAME = MyDatabase_Data, " + "FILENAME = ' " + DataFile + " ', " + "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " + "LOG ON (NAME = MyDatabase_Log, " + "FILENAME = ' " + LogFile + " ', " + "SIZE = 1MB, " + "MAXSIZE = 5MB, " + "FILEGROWTH = 10%) "; SqlCommand myCommand = new SqlCommand(str, myConn); try { myConn.Open(); myCommand.ExecuteNonQuery(); MessageBox.Show( "DataBase is Created Successfully ", "MyProgram ", MessageBoxButtons.OK, MessageBoxIcon.Information); return true; } catch (System.Exception ex) { MessageBox.Show(ex.ToString(), "MyProgram ", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } finally { if (myConn.State == ConnectionState.Open) { myConn.Close(); } } } 3楼 glacier111 2007-01-16 16:33:46 USE [master] create database ' " + DataBaseName + " ' 试试这个,不一定好使 4楼 lizhizhe2000 2007-01-16 16:35:06 不要加引号 5楼 yuanyuyuyu 2007-01-16 16:43:04 谢谢了!我是猪~~~55555555555 去掉破引号就好了 6楼 justrelax1 2008-12-20 20:39:02 该回复于2008-12-20 23:33:39被管理员删除
搜索墙@2009 www.pkwall.com all rights reserved QQ:276471788 [京ICP备09111534号]
声明:本站部分数据来源于网络,仅供参考,如有版权问题,请联系我们,我们将及时删除!转载本站请注明来源
| ||||||||||||||||||||||||||||||||||||||||