The C# code:
string sql = @"SELECT
CONVERT(VARCHAR, s.street_name) AS street_name,
CONVERT(VARCHAR, mc.management_company_name) AS management_company_name,
CONVERT(VARCHAR, tc.type_constuction_name) AS type_constuction_name,
FROM building_description bd
JOIN street s ON bd.Id_street = s.Id_street
JOIN management_company mc ON bd.Id_management_company = mc.Id_management_company
JOIN type_constuction tc ON bd.Id_type_constuction = tc.Id_type_constuction
“;
```
`using(SqlCommand command = new SqlCommand(sql, connection))
{
using(SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
DataInfo dataInfo = new()
{
Street = reader.GetString(reader.GetOrdinal("street_name")),
Type_constuction = reader.GetString(reader.GetOrdinal("type_constuction_name")),
Management_company_name = reader.GetString(reader.GetOrdinal("management_company_name")),
};
DataList.Add(dataInfo);
}
}
```
}`
`#The error:#
Exception thrown: ‘System.InvalidCastException’ in Microsoft.Data.SqlClient.dll
Unable to cast object of type ‘System.String’ to type ‘System.Int32’.
I expected that when the browser starts, a table appears with data from the building_description table
if you just display the table, the browser shows the table
string sql = “SELECT * FROM building_description;”;
maybe I’m missing the point where I replace the values to output the table to the browser or I have a mismatch in the index where the row is located in the database table
Дмитрий is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.