Ok, here an issue I'm facing here:
As part of the project requirements I'm working on I need to upload a file to a database tabl, and to dynamically build my INSERT statement that uploads that file using vb.net.
Here is what I have:
I have a database table called "Attachments", it's design is as follows:
Column (1) Label = "ID"
Column (1) type = PRIMARY KEY
Column (1) Data-Type = "int"
Column (2) Label = "AttachmentContent"
Column (2) type = NORMAL
Column (2) Data-Type = "varbinary(MAX)"
So now, if I want to insert a record into this table, I can do so like this in my VB code:
Dim MC as new MainClass
MC.DB("INSERT INTO Attachments (AttachmentContent) VALUES (XXXXXXXXXXXXXXXXXXXXXXX)")
See attachment "DB_CLASS.txt" that defines "MainClass"
Now, my issue is with the XXXXXXXXXXXXXXXXXXXXXXX above in my code
I tried to do it this way:
Dim filePath As String = "C:\Some_File.gif"
Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(Convert.ToInt32(fs.Length))
MC.DB("INSERT INTO Attachments (AttachmentContent) VALUES ('"+bytes.toString+"')")
It gives me an error because the insert statement that the system tries to execute becomes like this at run time:
INSERT INTO Attachments (AttachmentContent) VALUES ('System.Byte')
What am I missing here?