|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
storing image in Access tableive been searching for help with storing images in access. after much hunting i found this bit of code that Cor Ligthert put up on another forum. but when i try to update to the dataset, i get this error: system.argument. exception in system.data.dll, cannot change data type of a column once it has data. for one thing my column is empty, for another, i get that message even when i select "upload to dataset" without first selecting an image. can someone please help? \\\it needs a picturebox and four buttons on a page. Show quoteHide quote > Private abyt() As Byte thanks.> Private fo As New OpenFileDialog > Private sf As New SaveFileDialog > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > 'Reading a picture and put it in a bytearray > If fo.ShowDialog = DialogResult.OK Then > Dim fs As New IO.FileStream(fo.FileName, _ > IO.FileMode.Open) > Dim br As New IO.BinaryReader(fs) > abyt = br.ReadBytes(CInt(fs.Length)) > br.Close() > 'just to show the sample without a fileread error > Dim ms As New IO.MemoryStream(abyt) > Me.PictureBox1.Image = Image.FromStream(ms) > End If > End Sub > Private Sub Button2_Click(ByVal sender As System.Object, ByVal _ > e As System.EventArgs) Handles Button2.Click > 'writing a picture from a bytearray > If sf.ShowDialog = DialogResult.OK Then > Dim fs As New IO.FileStream(sf.FileName, _ > IO.FileMode.CreateNew) > Dim bw As New IO.BinaryWriter(fs) > bw.Write(abyt) > bw.Close() > End If > End Sub > Private Sub Button3_Click(ByVal sender As System.Object, ByVal _ > e As System.EventArgs) Handles Button3.Click > 'writing a bytearray to a dataset > Dim ds As New DataSet > ds.Tables.Add(New DataTable("Photo")) > ds.Tables(0).Columns.Add(New DataColumn("Sample")) > ds.Tables(0).Columns(0).DataType = > System.Type.GetType("System.Byte[]") > ds.Tables(0).Rows.Add(ds.Tables(0).NewRow) > ds.Tables(0).Rows(0)(0) = abyt > Dim sf As New SaveFileDialog > If sf.ShowDialog = DialogResult.OK Then > ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema) > End If > End Sub > Private Sub Button4_Click(ByVal sender As System.Object, _ > ByVal e As System.EventArgs) Handles Button4.Click > 'reading a picture from a dataset > Dim ds As New DataSet > If fo.ShowDialog = DialogResult.OK Then > ds.ReadXml(fo.FileName) > End If > abyt = CType(ds.Tables(0).Rows(0)(0), Byte()) > Dim ms As New IO.MemoryStream(abyt) > Me.PictureBox1.Image = Image.FromStream(ms) > End Sub > /// > > Cor Anewbie,
I tested the sample again and could not find really errors. (withouth a part that could go wrong in wrong sequence (try to read a dataset and than abording), I changed that). http://www.vb-tips.com/default.aspx?ID=0bf3f72d-b722-459d-8a46-38b5a2f7fdf0 However I have the idea that your problem has not to do with this, but just with reading and writing a dataset to/from an access database. Can you explain it a little bit more. Cor However in my idea "anewbie @ VB.NET via DotNetMonster.com" <u16975@uwe> schreef in bericht news:5b8e90a30b2ec@uwe...Show quoteHide quote > hi. > > ive been searching for help with storing images in access. after much > hunting i found this bit of code that Cor Ligthert put up on another > forum. > but when i try to update to the dataset, i get this error: > system.argument. > exception in system.data.dll, cannot change data type of a column once it > has > data. > > for one thing my column is empty, for another, i get that message even > when i > select "upload to dataset" without first selecting an image. > > can someone please help? > > \\\it needs a picturebox and four buttons on a page. >> Private abyt() As Byte >> Private fo As New OpenFileDialog >> Private sf As New SaveFileDialog > > >> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> System.EventArgs) Handles Button1.Click >> 'Reading a picture and put it in a bytearray >> If fo.ShowDialog = DialogResult.OK Then >> Dim fs As New IO.FileStream(fo.FileName, _ >> IO.FileMode.Open) >> Dim br As New IO.BinaryReader(fs) >> abyt = br.ReadBytes(CInt(fs.Length)) >> br.Close() >> 'just to show the sample without a fileread error >> Dim ms As New IO.MemoryStream(abyt) >> Me.PictureBox1.Image = Image.FromStream(ms) >> End If >> End Sub > > >> Private Sub Button2_Click(ByVal sender As System.Object, ByVal _ >> e As System.EventArgs) Handles Button2.Click >> 'writing a picture from a bytearray >> If sf.ShowDialog = DialogResult.OK Then >> Dim fs As New IO.FileStream(sf.FileName, _ >> IO.FileMode.CreateNew) >> Dim bw As New IO.BinaryWriter(fs) >> bw.Write(abyt) >> bw.Close() >> End If >> End Sub > > >> Private Sub Button3_Click(ByVal sender As System.Object, ByVal _ >> e As System.EventArgs) Handles Button3.Click >> 'writing a bytearray to a dataset >> Dim ds As New DataSet >> ds.Tables.Add(New DataTable("Photo")) >> ds.Tables(0).Columns.Add(New DataColumn("Sample")) >> ds.Tables(0).Columns(0).DataType = >> System.Type.GetType("System.Byte[]") >> ds.Tables(0).Rows.Add(ds.Tables(0).NewRow) >> ds.Tables(0).Rows(0)(0) = abyt >> Dim sf As New SaveFileDialog >> If sf.ShowDialog = DialogResult.OK Then >> ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema) >> End If >> End Sub > > >> Private Sub Button4_Click(ByVal sender As System.Object, _ >> ByVal e As System.EventArgs) Handles Button4.Click >> 'reading a picture from a dataset >> Dim ds As New DataSet >> If fo.ShowDialog = DialogResult.OK Then >> ds.ReadXml(fo.FileName) >> End If >> abyt = CType(ds.Tables(0).Rows(0)(0), Byte()) >> Dim ms As New IO.MemoryStream(abyt) >> Me.PictureBox1.Image = Image.FromStream(ms) >> End Sub >> /// >> >> Cor > > thanks. > > -- > Message posted via http://www.dotnetmonster.com hi! thanks for the help... i dont understand - why am i alone getting that
error! hmm. strange. anyhow, my problem is this: im creating a database for managing personnel records, and id like to have the employees passport sized photograph displayed in the main form. im able to store the file path properly, but i dont understand this image memory streaming bit. i was told theres an image load option in vb... would i be able to use that to upload, save and display my images? thanks -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-vb-net/200602/1 Anewbie,
I thought that the most problems were with Access in this the type of the datafield. I thought it was something as binary. Cor
System.IO.File.Exists
How can I read an XML string directly into a dataset without creating a file? Can I create windows form by using late binding? HTML in to readable/value accessible object Text file printout in dos mode through VB.Net or DOS command from VB.Net Help Displaying & Stabilizing PictureBox Contents passing a list as a parameter to a TableAdapter Fill method Designing A Process and Report Scheduler/Spooler Application run a dos command Loading HTML into an HTMLDoc problem |
|||||||||||||||||||||||