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 connString = "Data Source=\SQLEXPRESS;Initial Catalog=dbname; User ID=urID; Password=urPAss";
        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

Popular Posts

GREYCstoration Oil Paint plugin for Photoshop

Service Bus Gateway service stuck at Starting

PowerApps SubmitForm not clearing People Picker value

Apple iPhone sending SMS automatically 00447786205094

Download file failed signature verification and may have been tampered with - Workflow Manger 1.0 Refresh (CU2)