using System;
using System.Data;
using System.Data.SqlClient;
namespace Database_connection_Demo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");//lucida console
string connectionString = "server=.;database=sqlconnectiondemo;uid=sa;pwd=886566";
SqlConnection sqlconnection = new SqlConnection(connectionString);
sqlconnection.Open();
//insert new data to db after connecting
//string sql = "create table dbconnectiondemotable ( StudentID int identity,StudentName varchar(20) not null, Age int NOT NULL,Gender varchar(8))";
//SqlCommand command = new SqlCommand(sql, sqlconnection);
//command.ExecuteNonQuery();
string sql = "insert into dbconnectiondemotable(StudentName, Age, Gender) values('zhangsan', 33, 'male')";
SqlCommand command = new SqlCommand(sql, sqlconnection);
int result =command.ExecuteNonQuery();
if (result==1)
{
Console.WriteLine("insert successfullly!!!");
}
}
}
}