Data control methods for just one record

Hi,

I am making updatable pages for my website.

I am new to asp.net so I want to find the best method to pull one record from the database.

The record will consist of page name and page text. I have test information set up in the database which works of an ID and have constructed a database connection. But I want to use a database control which willl have minimum overhead for pulling out just one record. I won’t require any features such as editing or pagination.

I was thiking of using the data repeater.

any suggestions?

thanks for your advice.


  comm = new SqlCommand("SELECT m_name, m_text, m_id FROM pages WHERE m_id = 1", conn);

        try
        {
            conn.Open();
            reader = comm.ExecuteReader();
            if (reader.Read())
            {
                contentHeader.Text = "<h1>" + Server.HtmlEncode(reader["m_name"].ToString()) + "</h1>";
                contentText.Text = Server.HtmlEncode(reader["m_text"].ToString());
            }
            reader.Close();
        }
        finally
        {
            conn.Close();
        }



I am passing the header tag to asp:label and m_text to asp:literal.

My problem now that I have encoded all characters to html friendly. Not good when you have links. I will have to write a string replace method now to unencode specific characters based on a specific rules so that image linking, achore and h tags will work.

if there a asp.method that allows this or will I have to program it myself?

<asp:literal>

A data repeater is fine. You will want to bring back only 1 record with your query.

The quickest metod would be to use a SqlDataReader. Just make sure you select top 1 column names and not * as it will stop it from using indexes.

I hope that helps