SqlConnection myConn = new SqlConnection(@"Server=\SQLEXPRESS;Integrated security=True;Initial Catalog=master"); string query1 = "select name from sys.databases where name='test'"; SqlDataAdapter da = new SqlDataAdapter(query1 , myConn); DataTable dt = new DataTable(); myConn.Open(); da.Fill(dt); if (dt.Rows.Count == 0) { string query2 = " CREATE DATABASE [database_name] ON" + "( FILENAME ='test.mdf' )," + "( FILENAME ='test_log.ldf' )" + "FOR ATTACH ;"; SqlCommand myCommand = new SqlCommand(query2, myConn); myConn.Close(); myConn.Open(); myCommand.ExecuteNonQuery(); MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)