Dim fiStream As New FileStream(Server.MapPath("Images/thaicreate.jpg"), FileMode.Open)
Dim binReader As New BinaryReader(fiStream)
Dim pic() As Byte = {}
pic = binReader.ReadBytes(fiStream.Length)
// Used pic
fiStream.Close()
binReader.Close()
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim dtAdapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim strConnString, strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM member ORDER BY MemberID ASC "
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Dim dtMap As New DataTable("myMember") '*** DataTable Map DataSet.xsd ***'
Dim dr As DataRow
dtMap.Columns.Add(New DataColumn("MemberID", GetType(String)))
dtMap.Columns.Add(New DataColumn("Name", GetType(String)))
dtMap.Columns.Add(New DataColumn("Email", GetType(String)))
dtMap.Columns.Add(New DataColumn("Picture_Steam", GetType(System.Byte())))
Dim i As Integer = 0
For i = 0 To dt.Rows.Count - 1
Dim fiStream As New FileStream(Server.MapPath(dt.Rows(i)("Picture")), FileMode.Open)
Dim binReader As New BinaryReader(fiStream)
Dim pic() As Byte = {}
pic = binReader.ReadBytes(fiStream.Length)
dr = dtMap.NewRow
dr("MemberID") = dt.Rows(i)("MemberID")
dr("Name") = dt.Rows(i)("Name")
dr("Email") = dt.Rows(i)("Email")
dr("Picture_Steam") = pic
dtMap.Rows.Add(dr)
fiStream.Close()
binReader.Close()
Next
Dim rpt As New ReportDocument()
rpt.Load(Server.MapPath("myCrystalReport.rpt"))
rpt.SetDataSource(dtMap)
Me.CrystalReportViewer1.ReportSource = rpt
End Sub
End Class
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
SqlDataAdapter dtAdapter = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = null;
string strConnString = null;
string strSQL = null;
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
strSQL = "SELECT * FROM member ORDER BY MemberID ASC ";
objConn.ConnectionString = strConnString;
var _with1 = objCmd;
_with1.Connection = objConn;
_with1.CommandText = strSQL;
_with1.CommandType = CommandType.Text;
dtAdapter.SelectCommand = objCmd;
dtAdapter.Fill(ds);
dt = ds.Tables[0];
dtAdapter = null;
objConn.Close();
objConn = null;
DataTable dtMap = new DataTable("myMember"); //*** DataTable Map DataSet.xsd ***//
DataRow dr = null;
dtMap.Columns.Add(new DataColumn("MemberID", typeof(string)));
dtMap.Columns.Add(new DataColumn("Name", typeof(string)));
dtMap.Columns.Add(new DataColumn("Email", typeof(string)));
dtMap.Columns.Add(new DataColumn("Picture_Steam", typeof(System.Byte[])));
int i = 0;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
FileStream fiStream = new FileStream(Server.MapPath(dt.Rows[i]["Picture"].ToString()), FileMode.Open);
BinaryReader binReader = new BinaryReader(fiStream);
byte[] pic = { };
pic = binReader.ReadBytes((int)fiStream.Length);
dr = dtMap.NewRow();
dr["MemberID"] = dt.Rows[i]["MemberID"];
dr["Name"] = dt.Rows[i]["Name"];
dr["Email"] = dt.Rows[i]["Email"];
dr["Picture_Steam"] = pic;
dtMap.Rows.Add(dr);
fiStream.Close();
binReader.Close();
}
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("myCrystalReport.rpt"));
rpt.SetDataSource(dtMap);
this.CrystalReportViewer1.ReportSource = rpt;
}
}