What i can figure is you want o create database MyDatabase and use it on following commands
SqlConnection myConn1 = new SqlConnection("Server=SI-SI-MyUID\\SQLEXPRESSSUD;User ID=sa; Password=password; database=MyDatabaseData");
I would suggest some changes as
try
{
SqlConnection myConn = new SqlConnection("Server=SI-MyUID\\SQLEXPRESSSUD;User ID=sa; Password=password; database=master");
SqlConnection myConn1 = new SqlConnection("Server=SI-SI-MyUID\\SQLEXPRESSSUD;User ID=sa; Password=password; database=MyDatabase");
String str = "CREATE DATABASE MyDatabase ON PRIMARY " +
"(NAME = MyDatabase_Data, " +
"FILENAME = 'C:\\MyDatabaseData.mdf', " +
"SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = MyDatabase_Log, " +
"FILENAME = 'C:\\MyDatabaseLog.ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
SqlCommand myCommand = new SqlCommand(str, myConn);
String str1 = "CREATE TABLE myTable" +
"(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," +
"myName CHAR(50), myAddress CHAR(255), myBalance FLOAT)";
SqlCommand myCommand1 = new SqlCommand(str1, myConn1);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
<pre lang="vb">MessageBox.Show("DataBase is Created Successfully",
"MyProgram",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
myConn.Close();
myConn1.Open();
myCommand1.ExecuteNonQuery();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(),
"MyProgram",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
}
}
}
catch (Exception exp)
{
MessageBox.Show("Error\n"+exp);
throw;
}
}