1: function New-Row-sqlCE {
2: <#
3: .SYNOPSIS
4: Insert a row into a SQL CE table.
5:
6: .DESCRIPTION
7: Insert a row into a SQL CE table.
8:
9: .PARAMETER dbName
10: The value for the dbName field.
11:
12: .PARAMETER dbPath
13: The value for the dbPath field, if blank the current location
14: will be used.
15:
16: .PARAMETER tblName
17: The value for the tblName field, if blank the current location
18: will be used.
19:
20: .PARAMETER ArchiveName
21: The value for the ArchiveName field.
22:
23: .PARAMETER FileName
24: The value for the FileName field.
25:
26: .PARAMETER FileSizeKB
27: The value for the FileSizeKB field.
28:
29: .PARAMETER FileLastWriteTime
30: The value for the FileLastWriteTime field.
31:
32: .EXAMPLE
33: PS C:\> insert-sqlCEDB -ArchiveName 20120909 -FileLastWriteTime "09/09/2012" -FileName "file2" -FileSizeKB 1024
34: #>
35: [CmdletBinding()]
36: param(
37: [Parameter(Position=0, Mandatory=$true)]
38: [ValidateNotNullOrEmpty()]
39: [System.String]
40: $dbName,
41:
42: [Parameter(Position=1, Mandatory=$false)]
43: [System.String]
44: $dbPath,
45:
46: [Parameter(Position=3, Mandatory=$true)]
47: [ValidateNotNullOrEmpty()]
48: [System.String]
49: $tblName,
50:
51: [Parameter(Position=4, Mandatory=$true)]
52: [ValidateNotNullOrEmpty()]
53: [System.Int32]
54: $ArchiveName,
55:
56: [Parameter(Position=5, Mandatory=$true)]
57: [ValidateNotNullOrEmpty()]
58: [System.String]
59: $FileName,
60:
61: [Parameter(Position=6, Mandatory=$true)]
62: [ValidateNotNullOrEmpty()]
63: [System.Int32]
64: $FileSizeKB,
65:
66: [Parameter(Position=7, Mandatory=$true)]
67: [ValidateNotNull()]
68: [System.String]
69: $FileLastWriteTime
70: )
71:
72: Add-Type -Path "C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll";
73:
74: $connectionString = "Data Source=$dbPath$dbName.sdf;"
75:
76: $connection = New-Object "System.Data.SqlServerCe.SqlCeConnection" $connectionString
77: $command = New-Object "System.Data.SqlServerCe.SqlCeCommand"
78: $command.CommandType = [System.Data.CommandType]"Text"
79: $command.Connection = $connection
80:
81: $connection.Open()
82:
83: $command.CommandText = "INSERT INTO [$tblName] ([ArchiveName],[FileName],[FileSizeKB],[FileLastWriteTime]) VALUES ($ArchiveName,N'$FileName',$FileSizeKB,N'$FileLastWriteTime');"
84: $command.ExecuteNonQuery()
85:
86:
87: $command.Dispose()
88: $connection.Close();
89: $connection.Dispose;
90: }