To enter data for a continent, change the code as follows:
using System;
using System.Data.SqlClient;
namespace CountriesStatistics
{
class Countries
{
static int Main()
{
string strContinent = null;
string strArea = null;
string strPopulation = null;
Console.Write("Enter the name of the continent: ");
strContinent = Console.ReadLine();
Console.Write("Enter the area of the continent: ");
strArea = Console.ReadLine();
Console.Write("Enter the population of the continent: ");
strPopulation = Console.ReadLine();
string strInsert = "INSERT INTO Continents VALUES('" +
strContinent +
"', '" + strArea +
"', '" + strPopulation + "');";
SqlConnection conDatabase = new
SqlConnection("Data Source=(local);Database='Countries3';Integrated Security=yes");
SqlCommand cmdDatabase = new SqlCommand(strInsert, conDatabase);
conDatabase.Open();
cmdDatabase.ExecuteNonQuery();
conDatabase.Close();
return 0;
}
}
}
No comments:
Post a Comment