This C# program demonstrates how to create an SQL database for Microsoft SQL in C#.
using System;
using System.Data.SqlClient;
namespace CreateDatabase {
class Program {
static void Main(string[] args) {
Console.WriteLine(CreateDatebase("xoax"));
}
public static int CreateDatebase(string sDatabase) {
// The using block ensures that the connection is closed when it exits this block.
using (SqlConnection qConnection = new SqlConnection(
@"Server=localhost\SQLEXPRESS01;Trusted_Connection=True;")) {
qConnection.Open();
SqlCommand qCommand = qConnection.CreateCommand();
qCommand.CommandText = "CREATE DATABASE " + sDatabase;
return qCommand.ExecuteNonQuery();
}
}
}
}
-1 Press any key to continue . . .
© 20072025 XoaX.net LLC. All rights reserved.