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();的原因
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();的原因
解决方案 »
- WindowsCE中怎样解析Jason?
- vb webbrowser 如何等网页加载完了之后再进行下面操作。。。
- 数据库的修改 在线等
- 如何改变datagridview的标题,我的标题为我数据库的表字段名,如何改为中文名?
- ???C#操作xml?!!
- C#驱动摄像头问题,找了2周了,没找到答案
- c# datareceived事件 急急急
- ***********************请教一个关于IDisposable接口实现的问题***************
- 求教关于lucene.net盘古分词器的问题
- 关于DataGrid的数据源的问题
- 请教一条关于查询的Sql语句!!!
- SqlHelper 3.0 执行ExecuteReader 不能得到output问题
{
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();
}
}
}
试试这个,不一定好使