Just written to Program You need to add databases and tables to the SQL statements. The information you are looking for on the Internet is not comprehensive. I have sorted it out. The detailed information is as follows:
// __________________ Create a database ____________________
String connectionstring = "Data Source = localhost; Integrated Security = true; pooling = false ";
Sqlconnection conn = new sqlconnection (connectionstring );
Conn. open ();
SQL = "CREATE DATABASE clsky on primary (name = ABC, filename = 'e: \ clsky. MDF ')";
Sqlcommand cmd = new sqlcommand (SQL, Conn );
Cmd. executenonquery ();
MessageBox. Show ("the database is created successfully! ");
//_________________________________________________
// ________________ Create a table ___________________________
String connectionstring1 = "Data Source = localhost; initial catalog = clsky; Integrated Security = true; pooling = false ";
Sqlconnection conn1 = new sqlconnection (connectionstring1 );
Conn1.open ();
SQL = "CREATE TABLE clsky" +
"(ID integer constraint pkeymyid primary key," +
"Name char (50), address char (255), balance float )";
Sqlcommand cmd1 = new sqlcommand (SQL, conn1 );
Statement 1.executenonquery ();
MessageBox. Show ("the database is created successfully! ");
//__________________________________________________
// _______________ Delete a table _____________
SQL = "Drop table clsky ";
Sqlcommand cmd2 = new sqlcommand (SQL, conn1 );
Listen 2.executenonquery ();
MessageBox. Show ("Table deleted! ");
Conn1.close ();
Conn. Close ();
//_________________________________
If you want to delete this database, you can use:
String connectionstring = "Data Source = localhost; Integrated Security = true; pooling = false ";
Sqlconnection conn = new sqlconnection (connectionstring );
Conn. open ();
String SQL = "DROP DATABASE clsky ";
Sqlcommand cmd = new sqlcommand (SQL, Conn );
Cmd. executenonquery ();