Я пытаюсь добавить данные столбца из таблицы MS SQL в DropDownList: text = name, value = id < /p>
Year.DataTextField = reader["Name"].ToString();
Year.DataValueField = reader["Id"].ToString();
< /code>
Эти годы: 2021, 2022 и т. Д., Скажите, где я совершил ошибку? и что я должен указать в данных DataSource? < /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>
DataBinding: 'System.Data.common.datareCordinternal' не содержит свойства
afference с именем '2021'. < /p> < /p> < /p> < /p> < /p> < /p> < /p> br /> < /blockquote>
Подробнее здесь: https://stackoverflow.com/questions/794 ... -datarecor
Добавить DataSource в DropDownList: DataBinding Error: 'System.Data.common.datareCordInternal' не содержит свойства с им ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение