Simple code to connect sql server 2008 with c#
After wandering over the internet i got the most simplest code to connect c# with SQL server and get data in datatable or dataset.
string sql = @"select * from table";
SqlConnection conn = new SqlConnection(connString);
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(dt);
}
catch (Exception e)
{
Console.WriteLine("Error: " + e);
}
finally
{
conn.Close();
}
Comments
Post a Comment