Imports System Imports System.IO Imports System.Data Imports System.Data.OleDb
Class MainClass
Public Shared Sub Main(ByVal args As String()) Dim con As OleDbConnection = New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database\MSAccess\Test.mdb;User Id=admin;Password=") con.Open Dim cre As OleDbCommand = New OleDbCommand ("CREATE TABLE imgtest (id INTEGER PRIMARY KEY,img OLEObject)", con) cre.ExecuteNonQuery Dim imgfile As Stream = New FileStream ("C:\blue.jpg", FileMode.Open) Dim siz As Integer = imgfile.Length Dim imgdata(siz-1) As Byte imgfile.Read(imgdata, 0, imgdata.Length) imgfile.Close Dim ins As OleDbCommand = New OleDbCommand ("INSERT INTO imgtest VALUES(@id,@img)", con) ins.Parameters.Add("@id", OleDbType.Integer) ins.Parameters.Add("@img", OleDbType.VarBinary) ins.Parameters("@id").Value = 1 ins.Parameters("@img").Value = imgdata ins.ExecuteNonQuery Dim sel As OleDbCommand = New OleDbCommand ("SELECT img FROM imgtest WHERE id = @id", con) sel.Parameters.Add("@id", OleDbType.Integer) sel.Parameters("@id").Value = 1 Dim imgdata2 As Byte() = CType(sel.ExecuteScalar, Byte()) Dim drp As OleDbCommand = New OleDbCommand ("DROP TABLE imgtest", con) drp.ExecuteNonQuery Dim imgfile2 As Stream = New FileStream ("C:\blue2.jpg", FileMode.Create) imgfile2.Write(imgdata2, 0, imgdata2.Length) imgfile2.Close con.Close End Sub End Class
Hvis jeg skriver sådan her, kommer den ikke med fejl. Men den opretter heller ikke en ny tabel
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Visual Studio Projects\Software Serial Archive 2\bin\Data.mdb;User Id=admin;Password=") con.Open() Dim cre As OleDbCommand = New OleDbCommand("CREATE TABLE McAfee (id INTEGER,img OLEObject)", con) con.close()
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Visual Studio Projects\Software Serial Archive 2\bin\Data.mdb;User Id=admin;Password=") con.Open() Dim cre As OleDbCommand = New OleDbCommand("CREATE TABLE McAfee (id INTEGER,img OLEObject)", con) cre.ExecuteNonQuery ' <---------------------------------- con.close()
wee, det virker. Hvordan gør jeg så hvis jeg vil have flere kolonner? Lige nu kommer der jo kun en "img" ( integer ), hvad nu hvis jeg så også vil have en "navn" ( tekst ) ?
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.