سلام،
private string ConnectionString ="Integrated Security=SSPI;" +
"Initial Catalog=;" +
"Data Source=localhost;";
private SqlDataReader reader = null;
private SqlConnection conn = null;
private SqlCommand cmd = null;
private System.Windows.Forms.Button AlterTableBtn;
private string sql = null;
private System.Windows.Forms.Button CreateOthersBtn;
private System.Windows.Forms.Button button1;
private void ExecuteSQLStmt(string sql)
{
if( conn.State == ConnectionState.Open)
conn.Close();
ConnectionString ="Integrated Security=SSPI;" +
"Initial Catalog=mydb;" +
"Data Source=localhost;";
conn.ConnectionString = ConnectionString;
conn.Open();
cmd = new SqlCommand(sql, conn);
try
{
cmd.ExecuteNonQuery();
}
catch(SqlException ae)
{
MessageBox.Show(ae.Message.ToString());
}
}
// This method creates a new SQL Server database
private void CreateDBBtn_Click(object sender, System.EventArgs e)
{
// Create a connection
conn = new SqlConnection(ConnectionString);
// Open the connection
if( conn.State != ConnectionState.Open)
conn.Open();
string sql = "CREATE DATABASE mydb ON PRIMARY"
+"(Name=test_data, filename = 'C:\\mysql\\mydb_data.mdf', size=3,"
+"maxsize=5, filegrowth=10%)log on"
+"(name=mydbb_log, filename='C:\\mysql\\mydb_log.ldf',size=3,"
+"maxsize=20,filegrowth=1)" ;
ExecuteSQLStmt(sql);
}
یک لینک خوب: http://www.codeproject.com/KB/database/CreateDB.aspx
یک لینک خوب دیگر:
http://www.c-sharpcorner.com/UploadF...icallyMCB.aspx