How to get data in DataSet or DataTable with C#
The C# Part
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection mySqlConnection = new SqlConnection(connStr);
mySqlConnection.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Person", mySqlConnection);
da.Fill(dt);
<connectionStrings>
<add name="myConnectionString" connectionString="server=CHILLAX-339\SQLEXPRESS;database=TestingDB;Integrated Security=SSPI;"/>
</connectionStrings>
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection mySqlConnection = new SqlConnection(connStr);
mySqlConnection.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Person", mySqlConnection);
da.Fill(dt);
The Web.Config Part (windows authentication)
<connectionStrings>
<add name="myConnectionString" connectionString="server=CHILLAX-339\SQLEXPRESS;database=TestingDB;Integrated Security=SSPI;"/>
</connectionStrings>
Comments
Post a Comment