Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#/Crystal Reports:从数据库向报表显示图像时收到错误_C#_Crystal Reports_Dataset_Byte - Fatal编程技术网

C#/Crystal Reports:从数据库向报表显示图像时收到错误

C#/Crystal Reports:从数据库向报表显示图像时收到错误,c#,crystal-reports,dataset,byte,C#,Crystal Reports,Dataset,Byte,使用以下语法从数据库检索图像文件路径时,我当前收到一个错误: 列名命名为Image,数据类型为nvarchar。 我目前遇到的错误发布在下面 字符串的SourceColumn“Image”与字节[]的DataColumn“Image”之间存在不可转换的类型不匹配 不要使用nvarchar类型,请在此处使用BLOB示例: 代码片段 // Assumes that connection is a valid SqlConnection object. SqlCommand c

使用以下语法从数据库检索图像文件路径时,我当前收到一个错误:

列名命名为
Image
,数据类型为
nvarchar
。 我目前遇到的错误发布在下面

字符串的SourceColumn“Image”与字节[]的DataColumn“Image”之间存在不可转换的类型不匹配


不要使用nvarchar类型,请在此处使用BLOB示例: 代码片段

// Assumes that connection is a valid SqlConnection object.
            SqlCommand command = new SqlCommand(
              "SELECT pub_id, logo FROM pub_info", connection);

            // Writes the BLOB to a file (*.bmp).
            Stream stream;
            // Streams the BLOB to the FileStream object.
            BinaryWriter writer;

            // Size of the BLOB buffer.
            int bufferSize = 100;
            // The BLOB byte[] buffer to be filled by GetBytes.
            byte[] outByte = new byte[bufferSize];
            // The bytes returned from GetBytes.
            long retval;
            // The starting position in the BLOB output.
            long startIndex = 0;

            // The publisher id to use in the file name.
            string pubID = "";

            // Open the connection and read data into the DataReader.
            connection.Open();
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess);

            while (reader.Read())
            {
                // Get the publisher id, which must occur before getting the logo.
                pubID = reader.GetString(0);

                // Create a file to hold the output.
                stream = new MemoryStream();
                writer = new BinaryWriter(stream);

                // Reset the starting byte for the new BLOB.
                startIndex = 0;

                // Read bytes into outByte[] and retain the number of bytes returned.
                retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);

                // Continue while there are bytes beyond the size of the buffer.
                while (retval == bufferSize)
                {
                    writer.Write(outByte);
                    writer.Flush();

                    // Reposition start index to end of last buffer and fill buffer.
                    startIndex += bufferSize;
                    retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
                }

                // Write the remaining buffer.
                writer.Write(outByte, 0, (int)retval - 1);
                writer.Flush();

                // Close the output file.
                writer.Close();
                stream.Close();
            }

            // Close the reader and the connection.
            reader.Close();
            connection.Close();

            Image _Image = Image.FromStream(stream);





            System.Windows.Controls.Image _WPFImage = new System.Windows.Controls.Image();
            _WPFImage.Source = System.Windows.Media.Imaging.BitmapFrame.Create(stream);


    // Assumes that connection is a valid SqlConnection object.
            SqlCommand command = new SqlCommand(
              "SELECT pub_id, logo FROM pub_info", connection);

            // Writes the BLOB to a file (*.bmp).
            Stream stream;
            // Streams the BLOB to the FileStream object.
            BinaryWriter writer;

            // Size of the BLOB buffer.
            int bufferSize = 100;
            // The BLOB byte[] buffer to be filled by GetBytes.
            byte[] outByte = new byte[bufferSize];
            // The bytes returned from GetBytes.
            long retval;
            // The starting position in the BLOB output.
            long startIndex = 0;

            // The publisher id to use in the file name.
            string pubID = "";

            // Open the connection and read data into the DataReader.
            connection.Open();
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess);

            while (reader.Read())
            {
                // Get the publisher id, which must occur before getting the logo.
                pubID = reader.GetString(0);

                // Create a file to hold the output.
                stream = new MemoryStream();
                writer = new BinaryWriter(stream);

                // Reset the starting byte for the new BLOB.
                startIndex = 0;

                // Read bytes into outByte[] and retain the number of bytes returned.
                retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);

                // Continue while there are bytes beyond the size of the buffer.
                while (retval == bufferSize)
                {
                    writer.Write(outByte);
                    writer.Flush();

                    // Reposition start index to end of last buffer and fill buffer.
                    startIndex += bufferSize;
                    retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
                }

                // Write the remaining buffer.
                writer.Write(outByte, 0, (int)retval - 1);
                writer.Flush();

                // Close the output file.
                writer.Close();
                stream.Close();
            }

            // Close the reader and the connection.
            reader.Close();
            connection.Close();

            Image _Image = Image.FromStream(stream);





            System.Windows.Controls.Image _WPFImage = new System.Windows.Controls.Image();
            _WPFImage.Source = System.Windows.Media.Imaging.BitmapFrame.Create(stream);
// Assumes that connection is a valid SqlConnection object.
            SqlCommand command = new SqlCommand(
              "SELECT pub_id, logo FROM pub_info", connection);

            // Writes the BLOB to a file (*.bmp).
            Stream stream;
            // Streams the BLOB to the FileStream object.
            BinaryWriter writer;

            // Size of the BLOB buffer.
            int bufferSize = 100;
            // The BLOB byte[] buffer to be filled by GetBytes.
            byte[] outByte = new byte[bufferSize];
            // The bytes returned from GetBytes.
            long retval;
            // The starting position in the BLOB output.
            long startIndex = 0;

            // The publisher id to use in the file name.
            string pubID = "";

            // Open the connection and read data into the DataReader.
            connection.Open();
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess);

            while (reader.Read())
            {
                // Get the publisher id, which must occur before getting the logo.
                pubID = reader.GetString(0);

                // Create a file to hold the output.
                stream = new MemoryStream();
                writer = new BinaryWriter(stream);

                // Reset the starting byte for the new BLOB.
                startIndex = 0;

                // Read bytes into outByte[] and retain the number of bytes returned.
                retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);

                // Continue while there are bytes beyond the size of the buffer.
                while (retval == bufferSize)
                {
                    writer.Write(outByte);
                    writer.Flush();

                    // Reposition start index to end of last buffer and fill buffer.
                    startIndex += bufferSize;
                    retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
                }

                // Write the remaining buffer.
                writer.Write(outByte, 0, (int)retval - 1);
                writer.Flush();

                // Close the output file.
                writer.Close();
                stream.Close();
            }

            // Close the reader and the connection.
            reader.Close();
            connection.Close();

            Image _Image = Image.FromStream(stream);





            System.Windows.Controls.Image _WPFImage = new System.Windows.Controls.Image();
            _WPFImage.Source = System.Windows.Media.Imaging.BitmapFrame.Create(stream);


    // Assumes that connection is a valid SqlConnection object.
            SqlCommand command = new SqlCommand(
              "SELECT pub_id, logo FROM pub_info", connection);

            // Writes the BLOB to a file (*.bmp).
            Stream stream;
            // Streams the BLOB to the FileStream object.
            BinaryWriter writer;

            // Size of the BLOB buffer.
            int bufferSize = 100;
            // The BLOB byte[] buffer to be filled by GetBytes.
            byte[] outByte = new byte[bufferSize];
            // The bytes returned from GetBytes.
            long retval;
            // The starting position in the BLOB output.
            long startIndex = 0;

            // The publisher id to use in the file name.
            string pubID = "";

            // Open the connection and read data into the DataReader.
            connection.Open();
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess);

            while (reader.Read())
            {
                // Get the publisher id, which must occur before getting the logo.
                pubID = reader.GetString(0);

                // Create a file to hold the output.
                stream = new MemoryStream();
                writer = new BinaryWriter(stream);

                // Reset the starting byte for the new BLOB.
                startIndex = 0;

                // Read bytes into outByte[] and retain the number of bytes returned.
                retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);

                // Continue while there are bytes beyond the size of the buffer.
                while (retval == bufferSize)
                {
                    writer.Write(outByte);
                    writer.Flush();

                    // Reposition start index to end of last buffer and fill buffer.
                    startIndex += bufferSize;
                    retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
                }

                // Write the remaining buffer.
                writer.Write(outByte, 0, (int)retval - 1);
                writer.Flush();

                // Close the output file.
                writer.Close();
                stream.Close();
            }

            // Close the reader and the connection.
            reader.Close();
            connection.Close();

            Image _Image = Image.FromStream(stream);





            System.Windows.Controls.Image _WPFImage = new System.Windows.Controls.Image();
            _WPFImage.Source = System.Windows.Media.Imaging.BitmapFrame.Create(stream);