參考部份引用來源
--
重點在 ##3 這段的處理 (縮圖)
##1
Public Partial Class Form1
Inherits Form
Private dgv As DataGridView = Nothing
Public Sub New()
InitializeComponent()
'初始化动态产生数据表等字段
dgv = New DataGridView()
dgv.Parent = Me
dgv.Dock = DockStyle.Fill
Dim dt As New DataTable()
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("Image", GetType(Byte()))
dt.Rows.Add("Test1", File.ReadAllBytes("d:\test.jpg"))
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
dgv.DataSource = dt
End Sub
End Class
##2
Public Partial Class Form1
Inherits Form
Private dgv As DataGridView = Nothing
Public Sub New()
InitializeComponent()
'初始化动态产生数据表等字段
dgv = New DataGridView()
dgv.Parent = Me
dgv.Dock = DockStyle.Fill
Dim dt As New DataTable()
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("Image", GetType(String))
dt.Rows.Add("Test1", "d:\test.jpg")
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
dgv.Columns.Add(New DataGridViewTextBoxColumn() With { _
Key .HeaderText = "Name", _
Key .DataPropertyName = "Name" _
})
dgv.Columns.Add(New DataGridViewImageColumn() With { _
Key .HeaderText = "Image", _
Key .DataPropertyName = "Image" _
})
AddHandler dgv.CellFormatting, AddressOf New DataGridViewCellFormattingEventHandler(AddressOf dgv_CellFormatting)
dgv.DataSource = dt
End Sub
Private Sub dgv_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs)
If e.ColumnIndex = 1 AndAlso e.RowIndex <> dgv.NewRowIndex Then
e.Value = File.ReadAllBytes(dgv.Rows(e.RowIndex).Cells(1).Value.ToString())
End If
End Sub
End Class
##3
Public Partial Class Form1
Inherits Form
Private dgv As DataGridView = Nothing
Public Sub New()
InitializeComponent()
'初始化动态产生数据表等字段
dgv = New DataGridView()
dgv.Parent = Me
dgv.Dock = DockStyle.Fill
Dim dt As New DataTable()
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("Image", GetType(Byte()))
dt.Rows.Add("Test1", File.ReadAllBytes("d:\test.jpg"))
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
AddHandler dgv.CellFormatting,AddressOf New DataGridViewCellFormattingEventHandler(AddressOf dgv_CellFormatting)
dgv.AllowUserToAddRows = False
dgv.DataSource = dt
End Sub
Private Sub dgv_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs)
If e.ColumnIndex = 1 Then
Using oldms As New MemoryStream(DirectCast(e.Value, Byte()))
Dim img As Image = Image.FromStream(oldms)
Dim bt As New Bitmap(img, New Size(100, 100))
Using newms As New MemoryStream()
bt.Save(newms, ImageFormat.Jpeg)
e.Value = newms.ToArray()
End Using
End Using
End If
End Sub
End Class
##4
Public Partial Class Form1
Inherits Form
Private dgv As DataGridView = Nothing
Public Sub New()
InitializeComponent()
'初始化动态产生数据表等字段
dgv = New DataGridView()
dgv.Parent = Me
dgv.Dock = DockStyle.Fill
Dim dt As New DataTable()
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("Image", GetType(String))
dt.Rows.Add("Test1", "d:\test.jpg")
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
dgv.Columns.Add(New DataGridViewTextBoxColumn() With { _
Key .HeaderText = "Name", _
Key .DataPropertyName = "Name" _
})
dgv.Columns.Add(New DataGridViewImageColumn() With { _
Key .HeaderText = "Image", _
Key .DataPropertyName = "Image" _
})
AddHandler dgv.CellFormatting,AddressOf New DataGridViewCellFormattingEventHandler(AddressOf dgv_CellFormatting)
dgv.AllowUserToAddRows = False
dgv.DataSource = dt
End Sub
Private Sub dgv_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs)
If e.ColumnIndex = 1 Then
Dim bytes As Byte() = File.ReadAllBytes(e.Value.ToString())
Using oldms As New MemoryStream(bytes)
Dim img As Image = Image.FromStream(oldms)
Dim bt As New Bitmap(img, New Size(100, 100))
Using newms As New MemoryStream()
bt.Save(newms, ImageFormat.Jpeg)
e.Value = newms.ToArray()
End Using
End Using
End If
End Sub
End Class
2014年3月3日 星期一
vbnet OpenFileDialog 多選
引用來源
--
OpenFileDialog1.Multiselect = True '多選檔案
If Not e.Cancel Then
Dim i As Int16
ListBox1.Items.Clear()
For i = 0 To OpenFileDialog1.FileNames.Length - 1
ListBox1.Items.Add(OpenFileDialog1.FileNames(i))
Next
End If
--
OpenFileDialog1.Multiselect = True '多選檔案
If Not e.Cancel Then
Dim i As Int16
ListBox1.Items.Clear()
For i = 0 To OpenFileDialog1.FileNames.Length - 1
ListBox1.Items.Add(OpenFileDialog1.FileNames(i))
Next
End If
2014年3月2日 星期日
SQLite 取左右字串
select SUBSTR('1234',5,-2) --取右字串
select SUBSTR('1234',1,2) --取左字串
select length('1234') -- 取字串長度
2014年3月1日 星期六
selectcommand 不支援 updatecommand 動態 sql 的產生
VB.Net code to read data from excel 2003, 2007 and 2010
參考引用來源:VB.Net code to read data from excel 2003, 2007 and 2010
--
' Get Data from Excel 2003
Public Function GetExcel2003Data(ByVal PrmPathExcelFile As String, ByVal DataGrid1 As DataGrid)
Dim MyConnection As System.Data.OleDb.OleDbConnection
Try
'' Fetch Data from Excel
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source='" & PrmPathExcelFile & " '; " & "Extended Properties=Excel 8.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Attendence")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGrid1.DataSource = DtSet.Tables(0)
Catch ex As Exception
Throw ex
Finally
MyConnection.Close()
End Try
End Function
' Get Data from Excel 2007 or Excel 2010 ()
Public Function GetExcel2003Data(ByVal PrmPathExcelFile As String, ByVal DataGrid1 As DataGrid)
Dim MyConnection As System.Data.OleDb.OleDbConnection
Try
'' Fetch Data from Excel
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; " & _
"data source='" & PrmPathExcelFile & " '; " & "Extended Properties=Excel 12.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Attendence")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGrid1.DataSource = DtSet.Tables(0)
Catch ex As Exception
Throw ex
Finally
MyConnection.Close()
End Try
End Function
--
' Get Data from Excel 2003
Public Function GetExcel2003Data(ByVal PrmPathExcelFile As String, ByVal DataGrid1 As DataGrid)
Dim MyConnection As System.Data.OleDb.OleDbConnection
Try
'' Fetch Data from Excel
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source='" & PrmPathExcelFile & " '; " & "Extended Properties=Excel 8.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Attendence")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGrid1.DataSource = DtSet.Tables(0)
Catch ex As Exception
Throw ex
Finally
MyConnection.Close()
End Try
End Function
' Get Data from Excel 2007 or Excel 2010 ()
Public Function GetExcel2003Data(ByVal PrmPathExcelFile As String, ByVal DataGrid1 As DataGrid)
Dim MyConnection As System.Data.OleDb.OleDbConnection
Try
'' Fetch Data from Excel
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; " & _
"data source='" & PrmPathExcelFile & " '; " & "Extended Properties=Excel 12.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Attendence")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGrid1.DataSource = DtSet.Tables(0)
Catch ex As Exception
Throw ex
Finally
MyConnection.Close()
End Try
End Function
sqlite 檢查table是否存在
select count(*) from sqlite_master where table=***
SELECT count(*) FROM sqlite_master WHERE type='table' and name='" + TableName+ "'";
相關可參考:Caton + OO + Google =?: Sqlite
--
SELECT count(*) FROM sqlite_master WHERE type='table' and name='" + TableName+ "'";
相關可參考:Caton + OO + Google =?: Sqlite
--
C# 压缩 SQLite 数据库
C# 压缩 SQLite 数据库
当从SQLite数据库中删除数据时, 未用的磁盘空间将会加入一个内部的“自由列表”中。 当你下次插入数据时,这部分空间可以重用。磁盘空间不会丢失, 但也不会返还给操作系统。
如果删除了大量数据,而又想缩小数据库文件占用的空间,执行 VACUUM 命令。 VACUUM 将会从头重新组织数据库。这将会使用数据库有一个空的“自由链表”, 数据库文件也会最小。但要注意的是,VACUUM 的执行会需要一些时间 (在SQLite开发时,在Linux上,大约每M字节需要半秒种),并且, 执行过程中需要原数据库文件至多两倍的临时磁盘空间。
在SQLite ADO.Net中可以使用以下代码压缩SQLite数据库文件:SQLiteCommand cmd = new SQLiteCommand("VACUUM",sQLiteConnection);
cmd.ExecuteNonQuery();
壓縮SQLite的資料檔案
參考引用來源:壓縮SQLite的資料檔案
--
在使用SQLite資料庫時,發現程式執行刪除操作時,資料庫檔大小並沒有減小。查了相關資料後發現,當從 SQLite 刪除資料之後,未使用的磁碟空間被添加到一個內在的“空閒清單”中用於存儲你下次插入的資料。磁碟空間並沒有丟失,但是也不向作業系統返回磁碟空間。 如果想要減小資料庫檔,可以設置auto_vacuum標記,當開啟auto_vacuum,提交一個從資料庫中刪除資料的事務時,資料庫檔自動收縮。需要注意的是只有在資料庫未創建任何表時才能改變auto_vacuum標記。
在創建資料庫後首先執行以下語句,即可設置auto_vacuum標記。
m_db.execDML(_T("PRAGMA auto_vacuum = 1"));//(m_db為CppSQLite3DB物件)
還有另一種方法是執行vacuum命令
即時的插入和刪除會使得資料庫檔結構混亂,減慢對資料庫內容訪問的速度。 VACUUM命令複製主要資料庫檔到臨時資料庫並從臨時資料庫重新載入主要資料庫,以整理資料庫檔。這將除去空白頁,使表資料彼此相鄰排列,並整理資料庫檔結構。
代碼示例:
CString strSql = _T("VACUUM;");
m_db.execQuery(strSql);// (m_db為CppSQLite3DB物件)
兩個方法的區別在於:使用auto_vacuum僅僅是將空閒的頁除去,並不會像VACUUM那樣對資料庫進行磁碟重組,或是壓縮資料庫頁。
示例比較表:單位(位元組)
初始資料庫大小 插入5000條資料後 刪除所有資料
未做任何處理 7168 250880 250880
auto_vacuum標記 8192 252928 8192
執行vacuum命令 7168 250880 7167
備註:設置auto_vacuum標記後,資料庫會在內部存儲一些資訊以便支援這一功能,這使得資料庫檔比不開啟該選項時稍微大一些。
--
在使用SQLite資料庫時,發現程式執行刪除操作時,資料庫檔大小並沒有減小。查了相關資料後發現,當從 SQLite 刪除資料之後,未使用的磁碟空間被添加到一個內在的“空閒清單”中用於存儲你下次插入的資料。磁碟空間並沒有丟失,但是也不向作業系統返回磁碟空間。 如果想要減小資料庫檔,可以設置auto_vacuum標記,當開啟auto_vacuum,提交一個從資料庫中刪除資料的事務時,資料庫檔自動收縮。需要注意的是只有在資料庫未創建任何表時才能改變auto_vacuum標記。
在創建資料庫後首先執行以下語句,即可設置auto_vacuum標記。
m_db.execDML(_T("PRAGMA auto_vacuum = 1"));//(m_db為CppSQLite3DB物件)
還有另一種方法是執行vacuum命令
即時的插入和刪除會使得資料庫檔結構混亂,減慢對資料庫內容訪問的速度。 VACUUM命令複製主要資料庫檔到臨時資料庫並從臨時資料庫重新載入主要資料庫,以整理資料庫檔。這將除去空白頁,使表資料彼此相鄰排列,並整理資料庫檔結構。
代碼示例:
CString strSql = _T("VACUUM;");
m_db.execQuery(strSql);// (m_db為CppSQLite3DB物件)
兩個方法的區別在於:使用auto_vacuum僅僅是將空閒的頁除去,並不會像VACUUM那樣對資料庫進行磁碟重組,或是壓縮資料庫頁。
示例比較表:單位(位元組)
初始資料庫大小 插入5000條資料後 刪除所有資料
未做任何處理 7168 250880 250880
auto_vacuum標記 8192 252928 8192
執行vacuum命令 7168 250880 7167
備註:設置auto_vacuum標記後,資料庫會在內部存儲一些資訊以便支援這一功能,這使得資料庫檔比不開啟該選項時稍微大一些。
訂閱:
文章 (Atom)