Added collection of images from SQL datareader on ItextSharp - vb.net

I need to get a collection of images from a datareader or even from a datatable (if recommended to use this) of sql.
My intent is to populate the cell with the variable "myimage" (and I succeed perfectly)
In the variable "myimage2" I would like to insert the collection of images obtained from a datareader or a datatable, what can I do?
Currently I can insert only one image using the "getvalue" method as written in the code.
Dim connessione As New SqlConnection
Dim comando As New SqlCommand
connessione.ConnectionString = stringa_database
connessione.Open()
comando = connessione.CreateCommand()
comando.CommandType = CommandType.Text
comando.CommandText = "SELECT u.id_nota, u.immagine From immagini_aggiuntive u INNER JOIN note q ON q.id = id_nota where id_nota= " & id
Dim lettura As SqlDataReader = comando.ExecuteReader()
lettura.Read()
Dim imageByte2 As Byte() = CType(lettura.GetValue(1), Byte())
Dim ms2 As New MemoryStream(imageByte2, 0, imageByte2.Length)
Dim myImage2 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(ms2)
'fine blocco
Dim imageByte As Byte() = CType(row.Cells(11).Value, Byte())
Dim ms As New MemoryStream(imageByte, 0, imageByte.Length)
Dim myImage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(ms)
Dim cellimg As PdfPCell = New PdfPCell()
cellimg.AddElement(myImage)
cellimg.AddElement(myImage2)
pdfTable.AddCell(cellimg)
lettura.Close()
connessione.Close()

Related

parameter is not valid for image.fromstream()

Dim strsql As String
get data from access database in vb.net
Dim stream As System.IO.MemoryStream
Dim img As Image
strsql = " select HotelName,HotelAddress,HotelPhoneNum,HotelPicture,HotelDesc from Hotel_3Star where ID = " & intIndex & ";"
Dim cmd As New OleDbCommand(strsql, connection)
Dim myreader As OleDbDataReader
myreader = cmd.ExecuteReader
myreader.Read()
Dim nameHotel As String = myreader("HotelName")
Dim phoneNumHotel As String = myreader("HotelPhoneNum")
Dim descHotel As String = myreader("HotelDesc")
Dim PictHotel = myreader("HotelPicture")
stream = New System.IO.MemoryStream(CType(PictHotel, Byte()))
it says that the parameter is not valid
img = Image.FromStream(stream) 'here the error detected
lblHotelName.Text = nameHotel
lblPhoneNum.Text = phoneNumHotel
lblHotelDesc.Text = descHotel
pcbHotel.Image = img
connection.Close()

Insert & receive picture from ms access query db vb.net

so, I want to insert a picture to my ms-access DB and it works fine.
inserting code :
Dim ms As New System.IO.MemoryStream
Dim bmpImage As New Bitmap(GunaPictureBox1.Image)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
bytImage = ms.ToArray()
ms.Close()
Dim d As New DBConnect
d.Editdata(String.Format("INSERT INTO TeachersTable (TeacherFN, TeacherLN, [TeacherImage]) values('{0}','{1}','{2}')", GunaTextBox1.Text, GunaTextBox2.Text, bytImage))
display code :
Dim dt As DataTable = New DBConnect().selectdata(String.Format("SELECT [TeachersTable.TeacherImage] FROM TeachersTable where TeachersTable.ID= {0}", 1))
Dim EditTeacher As New EditTeacher
Dim pictureData As Byte() = DirectCast(dt.Rows(0)(1), Byte())
Dim stream As New IO.MemoryStream(pictureData)
EditTeacher.GunaPictureBox1.Image = Image.FromStream(stream)
EditTeacher.Show()
but now I want to display it on a picture box but when I execute the code its shows me an error said "Parameters is not valid" & I don't know where is the problem!

VB NET check SQL server image data type for null or empty

I need to check for null value of SQL server image data type ,
here is my code :
Dim cmd As New SqlCommand("select id_image1 from work_tbl where
work_id = 12345 ", conn)
Dim stream As New MemoryStream()
conn.Open()
Dim image As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
stream.Write(image, 0, image.Length)
conn.Close()
Dim bitmap As New Bitmap(stream)
picturebox1.Image = bitmap
I need to stop the procedure with msgbox if my image column is empty .
Dim cmd As New SqlCommand("select id_image1 from work_tbl where
work_id = 12345 ", conn)
Dim stream As New MemoryStream()
conn.Open()
if DBNull(cmd.ExecuteScalar())=false
Dim image As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
stream.Write(image, 0, image.Length)
Dim bitmap As New Bitmap(stream)
picturebox1.Image = bitmap
end if
conn.Close()

Digital Person fingerprint image retrieving

I am using the following code to save the finger print scanned through Digital Persona's device.
Dim cls As New ClsDataAccess
Dim con = New SqlConnection(cls.SqlConnectiontring)
Dim cmd As New SqlCommand
Dim str As New MemoryStream
Enroller.Template.Serialize(str)
Dim serializedTemplate As Byte() = str.ToArray()
'cmd.Parameters.Add(New SqlParameter("#fn", SqlDbType.VarChar, 10)).Value = "Joe"
'sql.DbType
Dim param(0) As SqlParameter
'Dim t As Integer = Join(serializedTemplate, ",")
param(0) = New SqlParameter("#biometricData", serializedTemplate)
'Public OnlineConnectionString As String = "Data Source = 203.234.5.678; Database = mydb; User CndID = username; Password = xxxxxx;"
'Dim cmd As New SqlCommand("Insert Into tbltestbio (biovalue) Values (#biometricData)", con)
'cmd.Parameters.Add(param)
Dim pictureParameter As SqlClient.SqlParameter = New SqlClient.SqlParameter("#Picture", SqlDbType.Binary)
pictureParameter.Value = serializedTemplate
cmd.Parameters.Add(pictureParameter)
The problem is that when I try to retrieve the image using memory stream like an ordinary image, it won't load. Any other image using my Object Browser is being displayed by this code. What am I doing wrong? Below is the code for image retrieval.
Sub ImageLoadFun(ByVal barrImg() As Byte)
Try
Dim ms As New MemoryStream(barrImg)
Dim returnImage As Image = Image.FromStream(ms)
PictureBox1.Image = returnImage.Image
EmployeeDrawPicture(img)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
It seems you get "template" from sensor and not "image".
Template is a list of minutiae and other info.
You need to check in your FingerPrint API if there's method to get image.
Be careful, usually image, from fingerprint sensor, is not in RGB format but in greyscale.

how to add new row after filling all textboxes, not replace old row in gridview?

i wrote program in vb.net. in my page, i have 3 textbox. in Txt_CardBarcode_TextChanged ,i wrote this codes:
Try
Dim stream_CardBarcode As System.IO.MemoryStream = New System.IO.MemoryStream
Dim cls As New Cls_Barcode
Dim pic_CardBarcode As System.Drawing.Image = Nothing
cls.btnEncode(pic_CardBarcode, Txt_CardBarcode.Text.Trim)
pic_CardBarcode.Save(stream_CardBarcode, System.Drawing.Imaging.ImageFormat.Png)
Dim f_cardBarcode As IO.FileStream = _
New IO.FileStream("C:\fafa.png", IO.FileMode.Create, IO.FileAccess.ReadWrite)
Dim b_cardBarcode As Byte() = stream_CardBarcode.ToArray
f_cardBarcode.Write(b_cardBarcode, 0, b_cardBarcode.Length)
f_cardBarcode.Close()
Dim ds As DS_Test
ds = New DS_Test
Dim Val_LabelBarcode() = {stream_CardBarcode.ToArray, Txt_ICCID.Text.Trim}
ds.Tables(2).Rows.Add(Val_LabelBarcode)
crp_CardBarcode.SetDataSource(ds.Tables(2))
Dim frm_CrpCardBarcode As New Frm_RepCardBarcode
frm_CrpCardBarcode.CrystalReportViewer1.ReportSource = crp_CardBarcode
GVSimInfo.DataSource = ds.Tables(2)
ds.Tables(2).Rows.Add(1)
GVSimInfo.Rows(GVSimInfo.Rows.Count - 1).Cells(0).Value = True
ds.Tables(2).Rows(0).Item(0) = True
ds.Tables(2).Rows(0).Item(1) = ""
ds.Tables(2).Rows(0).Item(2) = Txt_ICCID.Text
ds.Tables(2).Rows(0).Item(3) = ""
ds.Tables(2).Rows(0).Item(4) = ""
now, in run time, after filling 3textbox, new row add to gridview , but when user want to more than filling textboxes, new row in grid view replace on old row!!!
how to set new row add to grid view , instead of replace old row?
in my dataset, i put 3tables. tables(2) has 2 columns that save image barcode with byte array data type, but in my gridview ,i have 5 columns.
in run time give me error dialog,it is images from it:
If your DGV is not bound to any data Source:
GVSimInfo.Rows.Add(1);
If your DGV is bound to some Data Source then :
ds.Tables(2).Rows.Add(1)
Add this code after your last text box is filled and new row is needed.
to set the values you can use :
ds.Tables(2).Rows(0).Item("Column_number") = "your text"
Try
Dim stream_CardBarcode As System.IO.MemoryStream = New System.IO.MemoryStream
Dim cls As New Cls_Barcode
Dim pic_CardBarcode As System.Drawing.Image = Nothing
cls.btnEncode(pic_CardBarcode, Txt_CardBarcode.Text.Trim)
pic_CardBarcode.Save(stream_CardBarcode, System.Drawing.Imaging.ImageFormat.Png)
Dim f_cardBarcode As IO.FileStream = _
New IO.FileStream("C:\fafa.png", IO.FileMode.Create, IO.FileAccess.ReadWrite)
Dim b_cardBarcode As Byte() = stream_CardBarcode.ToArray
f_cardBarcode.Write(b_cardBarcode, 0, b_cardBarcode.Length)
f_cardBarcode.Close()
Dim ds As DS_Test
ds = New DS_Test
Dim Val_LabelBarcode() = {stream_CardBarcode.ToArray, Txt_ICCID.Text.Trim}
ds.Tables(2).Rows.Add(Val_LabelBarcode)
crp_CardBarcode.SetDataSource(ds.Tables(2))
Dim frm_CrpCardBarcode As New Frm_RepCardBarcode
frm_CrpCardBarcode.CrystalReportViewer1.ReportSource = crp_CardBarcode
ds.Tables(2).Rows.Add(1)
GVSimInfo.Rows(GVSimInfo.Rows.Count - 1).Cells(0).Value = True
ds.Tables(2).Rows(0).Item(0) = True
ds.Tables(2).Rows(0).Item(1) = ""
ds.Tables(2).Rows(0).Item(2) = Txt_ICCID.Text
ds.Tables(2).Rows(0).Item(3) = ""
ds.Tables(2).Rows(0).Item(4) = ""
GVSimInfo.DataSource = ds.Tables(2) <-------