I have installed Visual Studio Ultimate, and installed the Microsoft SQL Server, and tried to find my way around it, using some tutorials I found on line.
I have successfully compiled and run the following C# code:
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
SqlConnection sql = new SqlConnection("Data Source=.\\SQLEXPRESS;Integrated Security=True;User Instance=True");
sql.Open();
SqlCommand command = new SqlCommand("CREATE DATABASE newDatabase;", sql);
command.ExecuteNonQuery();
command.CommandText = "CREATE TABLE newTable (name VARCHAR(20), age INT)";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO newTable VALUES ('John', 29)";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO newTable VALUES ('Jack', 21)";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO newTable VALUES ('Robin', 22)";
command.ExecuteNonQuery();
command.CommandText = "SELECT * FROM newTable;";
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("{0} is {1} years old.",reader.GetString(0), reader.GetValue(1));
}
reader.Close();
sql.Close();
Console.ReadLine();
}
}
}
This will produce the right output, but now I want to actually see the newDatabase
data-base. So I search for the keyword 'sql', and found the 'Microsoft SQL Server Managment Studio', and opened it.
Unfortunately, I couldn't find my database there under Databases:
Where is it hiding and how can I find it?