 |
|
การดึงภาพในฐานข้อมูลมาแสดงใน Crystal Report บน Visual Studio (VB.NET) |
|
 |
|
|
 |
 |
|
ต้องใช้พวก Subreport ครับ ผมมีตัวอย่างการแทรกรุปภาพให้ดูครับ
Code (VB.NET)
'*** for Logo Sub Report (Start) ***'
Dim dtLogo As New DataTable("logo")
Dim dr As DataRow
dtLogo.Columns.Add(New DataColumn("Logo", GetType(System.Byte())))
dtLogo.Columns.Add(New DataColumn("Company", GetType(String)))
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)
dr = dtLogo.NewRow
dr("Logo") = pic
dr("Company") = "ThaiCreate.Com Co,. LTD"
dtLogo.Rows.Add(dr)
fiStream.Close()
binReader.Close()
'*** for Logo Sub Report (End) ***'

สร้าง Sub Report (Subreport) บน Crystal Report แบบ Step by Step (VB.NET /C#)
|
 |
 |
 |
 |
Date :
2016-01-13 12:00:05 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำแล้ว ภาพไม่แสดง ช่วยหน่อยค่ะ เป็นเพราะอะไรคะ

Code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim dtAdapter As New SqlDataAdapter
Dim DSreport As New DataSet()
Dim SqlReader As SqlClient.SqlDataReader
Dim Conn As New SqlClient.SqlConnection()
Dim ds As New DataSet
Dim dt As DataTable
Dim strConnString, strSQL As String
strConnString = "Server=192.168.0.42;Database=DBMT;user id=sa;password=P@ssw0rd"
' strSQL = "SELECT p.pro_code,p.pro_name,p.pro_cost,p.pro_min,p.pro_stock,u.u_unitname FROM MTcodeproducts p left join MTunit u on p.pro_unit=u.u_unitid where p.group_code='804' and p.pro_min < p.pro_stock "
strSQL = "SELECT * FROM MTmach WHERE pro_mach = '" & Me.TextBox1.Text & "' "
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds, "myDataTableHM")
dt = ds.Tables(0)
Conn = New SqlConnection(strConnString)
Conn.Open()
Dim DTT As New DataTable("myDataTableHM")
' DTT.Columns.Add("ID", GetType(String))
' DTT.Columns.Add("FName", GetType(String))
' DTT.Columns.Add("LName", GetType(String))
DTT.Columns.Add("mach_img", GetType(System.Byte()))
DSreport.Tables.Add(DTT)
Dim SqlAdapter As New SqlClient.SqlDataAdapter(strSQL, Conn)
SqlReader = SqlAdapter.SelectCommand.ExecuteReader
If SqlReader.HasRows Then
While SqlReader.Read
Dim path As String = Application.StartupPath + "\" + SqlReader.Item("mach_img").ToString()
Dim FilStr As New FileStream(path, FileMode.Open) ' เปิด file แบบ Stream เพื่ออ่านเป็น Binary
Dim BinRead As New BinaryReader(FilStr)
Dim DR As DataRow = DSreport.Tables("myDataTableHM").NewRow
' Add ข้อมูลที่อ่านจาก SQL Base ใส่เข้าไปแต่ละ Rows ของ Temp Table
' DR.Item("ID") = SqlReader.Item("ID")
' DR.Item("FName") = SqlReader.Item("FName")
' DR.Item("LName") = SqlReader.Item("LName")
' Column Photo ใส่ข้อมูล Binary
DR.Item("mach_img") = BinRead.ReadBytes(BinRead.BaseStream.Length)
DSreport.Tables("myDataTableHM").Rows.Add(DR) 'Add Row เข้าไปใน Temp Table
FilStr.Close() '//ปิด FileStream
BinRead.Close()
End While
SqlReader.Close()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Dim rpt As New ReportDocument()
Dim directory As String = My.Application.Info.DirectoryPath
'rpt.Load(directory & "\myCrystalReport1.rpt")
rpt.Load("D:\Program_ECF\MT\ECF_LOTUS\CrystalReportHmach.rpt")
rpt.SetDataSource(dt)
Me.CrystalReportViewer1.ReportSource = rpt
Me.CrystalReportViewer1.Refresh()
End If
End Sub
|
ประวัติการแก้ไข 2016-01-13 16:37:07
 |
 |
 |
 |
Date :
2016-01-13 16:29:59 |
By :
nunan13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Filed ที่ลากเข้าไปใน Crystal Report เป็น Byte หรือยังครับ
|
 |
 |
 |
 |
Date :
2016-01-13 16:44:04 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนผู้รู้ ช่วยหน่อยค่ะ ยังติดอยู่เลยค่ะ รูปไม่โชว์
|
 |
 |
 |
 |
Date :
2016-01-14 14:25:45 |
By :
nunan13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จริง ๆ แล้วมันแค่ set filed ให้เป็น byty() ก็ใช้ได้แล้วครับ
แต่ผมสงสัยตรง filed ที่เอาเข้าในไปใน crystal report มากกว่า
ลองเอา mouse ไปวางที่รูปภาพดูครับ ว่ามันขึ้นว่า Blob Field หรือปล่าว
อันนี้ผมทำตัวอย่างให้ดู
https://drive.google.com/file/d/0B_86m1NvJJzOLVZ0eTN3RnMyS2c/view?usp=sharing
|
 |
 |
 |
 |
Date :
2016-01-15 08:36:33 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่าเข้าจองกระทู้ใช้ DataBase fields การจาก query จาก Base ตรง แบบโยน Parameter Where มา ซึ่งจากที่ดูจาก DataBase เก็บเป้น Path File รูปไว้ ซึ่งจากที่ดูใน Internet เค้าจะแนะนำว่า ให้ทำการใช้ Dataset ของ .net ช่วย โดยสร้าง Add Dataset เข้ามาใน โปรเจค จากนั้นสร้าง Column Byte() เข้าไป แล้วเขียน Code query จาก Database convert จาก path File เป้น Byte() แล้วจากนั้นก็โยน DataSet เค้า report แทน ซึ่ง Crystal report มองว่าเป็น Byte() มันจะเป้นรูปเองครับ
ลองดูนะครับ
|
 |
 |
 |
 |
Date :
2016-01-15 10:30:51 |
By :
joevoy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองโหลดใหม่ดูครับ
http://www.drop4shared-remove-by-admin.com/d495f7ce
ทำไม filed โชว์เป็น string ล่ะครับ
filed ผมขึ้นแบบนี้น่ะครับ

|
 |
 |
 |
 |
Date :
2016-01-15 14:40:34 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมใช้ 2013 อ่ะครับ T__T
ลองเปิด VS2010 ขึ้นมาก่อน
แล้วกด Open จาก VS ดูครับ
อย่า double click ที่ไฟล์โดยตรง
|
 |
 |
 |
 |
Date :
2016-01-15 15:32:08 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
http://stackoverflow.com/questions/20486230/how-to-convert-visual-studios-2013-project-to-visual-studios-2010
|
 |
 |
 |
 |
Date :
2016-01-15 15:38:42 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังทำไม่ได้เลย รบกวนช่วยหน่อยค่ะ
|
 |
 |
 |
 |
Date :
2016-01-16 09:46:37 |
By :
nunan13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
columnที่สร้างเพื่อแสดงรูปภาพ ใน .xsd ต้องให้เป็นประเภท system.byte() มีวงเล็บด้วยนะ
|
 |
 |
 |
 |
Date :
2018-07-28 15:38:09 |
By :
สุนทร |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|