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 cmd As OleDbCommand = New OleDbCommand ("SELECT * FROM T1", con) Dim rdr As OleDbDataReader = cmd.ExecuteReader While rdr.Read Dim f1 As Integer = CType(rdr(0), Integer) Dim f2 As String = CType(rdr(1), String) Console.WriteLine(f1 & " " & f2) End While con.Close End Sub End Class
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
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.