 |
|
การนำรูปไปโชวใน Gridview โดยเก็บเฉพาะชื่อรูปใน DB และมี pathg เฉพาะในตัวโปรแกรม โดยสามารถอัพโหลดเก็บไฟล์ใน directory ที่ต้องการ |
|
 |
|
|
 |
 |
|
ขอบคุณสำหรับ ลิงค์นะครับผม
คือผมไม่เข้าใจตรง ที่ว่า
1.ผมจะดึงรูปจาก path ของผมยังไง เช่น C:/interrub/wwwroot/XXX..../ (ปกติเค้าจะทำโพสเดอร์ไว้ใน ตัวโปรแจ็ค แต่ผมต้องการดึงจากนอกโปรแจ็คอะครับ)
2.ผมมีชื่อรูปในดาต้าเบส ผมต้องการให้มันดึง โดยชื่อกับรูปให้ตรงกัน
ตอนนี้งงมากครับ ติดแค่ 2 ข้อนี่อะครับ รบกวนผู้รู้ใจช่วยไขข้อกระจ่างด้วยนะครับ
|
 |
 |
 |
 |
Date :
2015-12-15 16:37:42 |
By :
dendeenarat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูเอาครับ WinApp
Code (VB.NET)
If dt.Rows.Count > 0 Then
find = True
' dt.Columns("productpic").DataType = System.Type.GetType("System.Byte[]")
'dt.Columns.Add("CarImageData", GetType(Byte()))
'For Each row As DataRow In dt.Rows
' row.SetField(Of Byte())("CarImageData", IO.File.ReadAllBytes(row.Field(Of String)("productpic")))
'Next
'*******************สร้าง Column เก็บรูปภาพใน DataGridView****************************************
dgv1.DataSource = dt
' If dgv1.Columns.Contains("ColImg") Then
With dgv1
.DefaultCellStyle.BackColor = Color.Azure
.AlternatingRowsDefaultCellStyle.BackColor = Color.White
.Columns("id").HeaderText = "ID"
.Columns("productname").HeaderText = "PRODUCT NAME"
.Columns("dateimport").HeaderText = "DATE IMPORT"
.Columns("dateexs").HeaderText = "DATE EXISTS"
.Columns("quantity").HeaderText = "QUANTITY"
.Columns("price").HeaderText = "PRICE"
.Columns("unitprice").HeaderText = "UNIT"
.Columns("productpic").HeaderText = "FILE PATH"
End With
' Else
'กำหนดความสูงของ Column
For Each row As DataGridViewRow In dgv1.Rows
If row.IsNewRow Then Continue For
row.Height = CInt(row.Height * 5)
Next
' Dim img As New DataGridViewImageCell
'สร้าง Column ไว้แสดงรูปภาพ
Dim ColImage As New DataGridViewImageColumn
If (dgv1.Columns.Contains("ColImg")) Then
Else
ColImage.Name = "ColImg"
ColImage.HeaderText = "PICTURE"
dgv1.Columns.Add(ColImage)
'ColImage.ImageLayout = DataGridViewImageCellLayout.Stretch
ColImage.ImageLayout = DataGridViewImageCellLayout.Zoom
End If
'ดึง Path ไฟล์เข้าไปใน DataGridview
For i As Integer = 0 To dt.Rows.Count - 1
Dim inImg As Image = Image.FromFile(dt.Rows(i)(7))
dgv1.Rows(i).Cells("ColImg").Value = inImg
Next
' End If
|
 |
 |
 |
 |
Date :
2015-12-15 18:02:28 |
By :
parinya-t |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวอย่างครับ

|
 |
 |
 |
 |
Date :
2015-12-16 08:55:20 |
By :
parinya-t |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนขอโค้ดตัวเต็มได้ไหมครับ จะเอาไปศึกษา
|
 |
 |
 |
 |
Date :
2015-12-17 10:49:35 |
By :
dendeenarat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่รู้ได้หรือยังครับ ลองดูนะครับ ถ้ายังไม่ตรงตามความต้องการก็บอกได้นะครับ
Code (VB.NET)
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim table = New DataTable()
Dim ImageColumn As New DataGridViewImageColumn
With ImageColumn
.Width = 15
.DefaultCellStyle.NullValue = Nothing
.ImageLayout = DataGridViewImageCellLayout.Zoom
End With
DataGridView1.Columns.Add(Nothing, "Id")
DataGridView1.Columns.Add(Nothing, "Product Name")
DataGridView1.Columns.Add(Nothing, "Picture")
DataGridView1.Columns.Add(ImageColumn)
'//create schema
table.Columns.Add("Id", GetType(Integer))
table.Columns.Add("ProductName", GetType(String))
table.Columns.Add("Picture", GetType(String))
'//add sample rows
table.Rows.Add(1, "N1", "DSCN6860")
table.Rows.Add(2, "N2", "DSCN6864")
table.Rows.Add(3, "N3", "DSCN6865")
table.Rows.Add(4, "N4", "DSCN6868")
Dim bmp As Bitmap
'Dim counter As Integer
Dim pPaht As String
For Each row As DataRow In table.Rows
pPaht = "C:\Users\Bundit\Pictures\" + row.Field(Of String)("Picture") + ".JPG"
bmp = New Bitmap(pPaht, True)
DataGridView1.Rows.Add(row.Field(Of Integer)("Id"), row.Field(Of String)("ProductName"), row.Field(Of String)("Picture"), bmp)
Next
End Sub
End Class

|
 |
 |
 |
 |
Date :
2015-12-17 13:48:40 |
By :
บัญดิษฐ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เนื่องจากผมจะลองประยุกต์ใช้ กับ การดึงข้อมูลจากดาต้าเบส อันนี้เป็นดาต้าเบสที่เก็บชื่อรูปภาพ

โดยผมทำบนเว็บแอ๊พครับ นี้เป็นการ join ข้อมูลเพื่อทำการดึงข้อมูล 2 เทเบิ้ลมาร่วมกัน

ผมมีโฟรเดอร์ที่เก็บรูปภาพตรง "C:\inetpub\wwwroot\CharmingWS\Pictures\PRODUCT"
ผมยัง งง อยู่ว่าจะนำ Path รูปมาร่วมกับชื่อรูปใน Database ยังไงเพื่อดึงมาโชว์ใน Gridview อะครับ ขอบคุณทุกคำตอบที่คอยช่วยเหลือนะครับ
เดียวจะงม ตามตัวอย่างที่ได้รับดูด้วยครับ
|
 |
 |
 |
 |
Date :
2015-12-18 10:29:36 |
By :
dendeenarat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
For Each row As DataRow In table.Rows
pPaht = "C:\Users\Bundit\Pictures\" + row.Field(Of String)("Picture") + ".JPG"
bmp = New Bitmap(pPaht, True)
DataGridView1.Rows.Add(row.Field(Of Integer)("Id"), row.Field(Of String)("ProductName"), row.Field(Of String)("Picture"), bmp)
Next
ถ้าผมเอามาประยุกต์ใช้กับ webfrom ต้องแก้แบบไหนครับ ลองแล้วไม่ได้
|
 |
 |
 |
 |
Date :
2015-12-18 16:27:19 |
By :
dendeenarat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO10 เผื่อกึ๋นไม่พอ
ุถ้าเอาขึ้น Server จริง ต้องกำหนดสิทธิ์ให้กับ IUSER ให้สามารถเข้าถึง(อ่าน) โฟล์เดอร์ C:\ExternaImages ได้
|
 |
 |
 |
 |
Date :
2015-12-18 17:34:43 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO10 มีอีก 1 วิธีนั่นคือสร้าง virtual directory บน IIS
"มันอยู่นอกโปรเจคก็หลอกมันว่าอยู่ในโปรเจค"

ปล. จริงฯคิดได้ร้อยแปดพันเก้าแต่พิมพ์ไม่ทัน
|
 |
 |
 |
 |
Date :
2015-12-18 17:57:56 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|