Есть следующий код, но при вызове таблицы product, появляется много ошибок, о считывании…
- User
Есть следующий код, но при вызове таблицы product, появляется много ошибок, о считывании bytea, хотя данный код должен конвертировать bytea в string. Как это решить? string query = "SELECT product_id, product_type_id, sheet_count, paper_denisty_id, paper_type_id, sheet_format_id, binding_type_id, picture FROM product";
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString)) { connection.Open(); NpgsqlCommand command = new NpgsqlCommand(query, connection); using (NpgsqlDataReader reader = command.ExecuteReader()) { DataTable dataTable = new DataTable(); dataTable.Columns.Add("product_id", typeof(int)); dataTable.Columns.Add("product_type_id", typeof(int)); dataTable.Columns.Add("sheet_count", typeof(int)); dataTable.Columns.Add("paper_denisty_id", typeof(int)); dataTable.Columns.Add("paper_type_id", typeof(int)); dataTable.Columns.Add("sheet_format_id", typeof(int)); dataTable.Columns.Add("binding_type_id", typeof(int)); dataTable.Columns.Add("picture", typeof(string)); while (reader.Read()) { DataRow newRow = dataTable.NewRow(); newRow["product_id"] = reader["product_id"]; newRow["product_type_id"] = reader["product_type_id"]; newRow["sheet_count"] = reader["sheet_count"]; newRow["paper_denisty_id"] = reader["paper_denisty_id"]; newRow["paper_type_id"] = reader["paper_type_id"]; newRow["sheet_format_id"] = reader["sheet_format_id"]; newRow["binding_type_id"] = reader["binding_type_id"]; try { newRow["picture"] = BitConverter.ToString((byte[])reader["picture"]); } catch (InvalidCastException) { newRow["picture"] = DBNull.Value; } dataTable.Rows.Add(newRow); } dataGridView1.DataSource = dataTable; } } rows_Count_Label.Text = dataGridView1.RowCount.ToString(); - Assistant
Для решения данной проблемы, попробуйте заменить SqlDataReader с использованием GetOrdinal и затем GetValue методами для получения данных: