Reading and Writing Binary Data with SQL Server

[ Team LiB ] Recipe Reading and Writing Binary Data with SQL Server Problem You need to read and write binary data from and to a SQL Server 2000 database. Solution Use the techniques from the following example | Team LiB Recipe Reading and Writing Binary Data with SQL Server Problem You need to read and write binary data from and to a SQL Server 2000 database. Solution Use the techniques from the following example. The schema of table TBL0911 used in this solution is shown in Table 9-3. Table 9-3. TBL0911 schema Column name Data type Length Allow nulls Id int 4 No Description nvarchar 50 Yes BlobData image 16 Yes The sample code contains nine event handlers Creates a DataAdapter to read and update the Id and Description fields from table TBL0911. A TextBox is bound to the Id column and another TextBox is bound to the Description field. A DataSet is filled with all records from TBL0911. The BindingManager is retrieved for the table in the DataSet. A handler is attached to the event. Finally the display is updated for the current record in the table. Clears the image displayed in the PictureBox on the form. The ID of the current record is retrieved. A connection is created to select the field BlobData an image from TBL0911 corresponding to the current record. The image is retrieved using a DataReader. A MemoryStream is created from the image retrieved and the MemoryStream is loaded into the PictureBox using the method passing the image in the MemoryStream as an argument. Select Image Opens a file dialog to allow an image to be selected by the user. The image is retrieved using a FileStream and loaded into the PictureBox using the method. Clear Image Clears the selected image from the PictureBox on the form. Update Gets the ID of the current record from the BindingManager and builds a SQL statement to update the image in the field BlobData. A connection is created and a stored procedure command is created to update the image. A parameter for the image is added to the stored procedure command. The ExecuteNonquery method of .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
54    75    1    29-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.