Кто-нибудь знает, почему следующее не работает?Сообщение об ошибке компилятора: CS0021
C#:
public partial class Default : System.Web.UI.Page
{
SqlConnection connection;
SqlCommand command;
SqlDataReader reader;
protected void Page_Load(object sender, EventArgs e)
{
using (connection = new SqlConnection(ConfigurationManager.AppSettings["connString"]))
{
using (command = new SqlCommand("select col1, col2 from table1 where id = @id", connection))
{
command.Parameters.Add("@id", SqlDbType.Int, 3).Value = 1;
connection.Open();
using (reader = command.ExecuteReader())
{
reader.Read();
Div1.InnerHtml = reader.Read["col1"].ToString();
}
}
}
}
}
HTML:
<div runat="server" id="Div1"></div>
Ошибка:
Compiler Error Message: CS0021: Cannot apply indexing with [] to an expression of type 'method group'
Line 32: Div1.InnerHtml = reader.Read["col1"].ToString();