IW1QLH

  • Increase font size
  • Default font size
  • Decrease font size

Read from a table in a database

E-mail Print PDF
ASPX.CS C# - How to read from a table in a database


SqlConnection conn = new SqlConnection("...");
conn.Open();

SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT Description, Position FROM TableName";

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
   Desc = Convert.ToString(dr["Description"]);
   Pos = Convert.ToDouble(dr["Position"]);

   ...
}

dr.Close();
conn.Close()


{moscomment}

Last Updated on Friday, 27 October 2006 16:12