using System;
using System.Data.SqlClient;
namespace ConsoleApp1
{
class ProgramDb
{
static void Main(string[] args)
{
string connString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SampleDb;Integrated Security=SSPI";
//Create the connection object
SqlConnection con = new SqlConnection(connString);
try {
SqlCommand cm = new SqlCommand("select * from Student", con);
con.Open();
Console.WriteLine("Connection Successfully");
SqlDataReader sdr = cm.ExecuteReader();
while (sdr.Read())
{
Console.WriteLine(sdr["name"]);
}
Console.ReadKey();
}
catch (Exception e) {
Console.WriteLine(e);
}
finally
{
con.Close();
}
}
}
}
No comments:
Post a Comment