C# Database Connections and Queries

Create connection string:SqlConnection conn = new SqlConnection("Data Source=DATASOURCE\\\\SQLEXPRESS;Initial Catalog=DATABASE_NAME;Integrated Security=True");

try
{
conn.Open();
SqlCommand sql = new SqlCommand("SELECT * FROM tableName", conn);
SqlDataReader reader = sql.ExecuteReader();

while (reader.Read())
{
this.TARGET_ID.InnerHtml += reader["column"] ;
}
}
catch (SqlException sqle)
{
sqle.Message.ToString();
}

This site uses Akismet to reduce spam. Learn how your comment data is processed.