Код: Выделить всё
Year.DataTextField = reader["Name"].ToString();
Year.DataValueField = reader["Id"].ToString();
< /code>
Эти годы присутствуют: 2021, 2022 и т. Д. < /p>
Можете ли вы сказать мне, где я сделал ошибку? И что я должен указать в данных данных
string query = @"SELECT Id, Name, Status FROM Period";
// Define the connection string to the SQL Server database
string connectionString = "Data Source=TEST;Initial Catalog=Test1;Integrated Security=SSPI";
// Create a SqlConnection object to connect to the database
using (SqlConnection connection = new SqlConnection(connectionString))
{
// Open the database connection
connection.Open();
// Create a SqlCommand object to execute the query
using (SqlCommand command = new SqlCommand(query, connection))
{
// Execute the query and retrieve the results
using (SqlDataReader reader = command.ExecuteReader())
{
// Loop through the rows and retrieve the column names
while (reader.Read())
{
Year.DataSource = reader;
Year.DataTextField = reader["Name"].ToString();
Year.DataValueField = reader["Id"].ToString();
Year.DataBind();
}
}
}
}
< /code>
Я получаю эту ошибку: < /p>
DataBinding: 'System.data.common.datareCordInternal' не содержит свойства с именем '2021'.
Подробнее здесь: https://stackoverflow.com/questions/794 ... -datarecor