Skip to content

Commit 78a0510

Browse files
tduguidtduguid
authored andcommitted
Fix to insert datatable record
1 parent b94d14c commit 78a0510

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

CS/Scripts/Data.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static void CreateTableAliasTable()
6262
da.Fill(TableAliasTable);
6363
}
6464
TableAliasTable.DefaultView.Sort = columnName + " asc";
65-
DateFormatTable.TableName = tableName;
65+
TableAliasTable.TableName = tableName;
6666

6767
}
6868
catch (Exception ex)
@@ -213,7 +213,7 @@ public static void InsertRecord(DataTable tbl, string text)
213213
{
214214
string tableName = tbl.TableName.ToString();
215215
string columnName = tbl.Columns[0].ColumnName.ToString();
216-
string sql = "SELECT * FROM " + tableName; //+ " ORDER BY " + columnName;
216+
string sql = "SELECT * FROM " + tableName + " ORDER BY " + columnName;
217217
if (tbl.Select(columnName + " = '" + text.Replace("'", "''") + "'").Length == 0)
218218
{
219219
DialogResult dr = MessageBox.Show("Would you like to add '" + text + "' to the list?", "Add New Value", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

VB/Scripts/Data.vb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Imports System.IO
33
Imports System.Data
44
Imports System.Data.SqlServerCe
55
Imports System.Security.AccessControl
6+
Imports System.Windows.Forms
67

78
Namespace Scripts
89

@@ -38,6 +39,7 @@ Namespace Scripts
3839
End Using
3940

4041
TableAliasTable.DefaultView.Sort = columnName & Convert.ToString(" asc")
42+
TableAliasTable.TableName = tableName
4143

4244
Catch ex As Exception
4345
'ErrorHandler.DisplayMessage(ex)
@@ -64,6 +66,7 @@ Namespace Scripts
6466
End Using
6567

6668
DateFormatTable.DefaultView.Sort = columnName & Convert.ToString(" asc")
69+
DateFormatTable.TableName = tableName
6770

6871
Catch ex As Exception
6972
'ErrorHandler.DisplayMessage(ex)
@@ -145,6 +148,38 @@ Namespace Scripts
145148

146149
End Sub
147150

151+
Public Shared Sub InsertRecord(ByVal tbl As DataTable, ByVal text As String)
152+
Dim tableName As String = tbl.TableName.ToString()
153+
Dim columnName As String = tbl.Columns(0).ColumnName.ToString()
154+
Dim sql As String = "SELECT * FROM " & tableName
155+
If tbl.[Select](columnName & " = '" + text.Replace("'", "''") & "'").Length = 0 Then
156+
Dim dr As DialogResult = MessageBox.Show("Would you like to add '" & text & "' to the list?", "Add New Value", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
157+
Select Case dr
158+
Case DialogResult.Yes
159+
tbl.Rows.Add(New Object() {text})
160+
Dim cn As SqlCeConnection = New SqlCeConnection(Data.Connection())
161+
Dim scb As SqlCeCommandBuilder = Nothing
162+
Dim sda As SqlCeDataAdapter = New SqlCeDataAdapter(sql, cn)
163+
sda.TableMappings.Add("Table", tableName)
164+
scb = New SqlCeCommandBuilder(sda)
165+
sda.Update(tbl)
166+
Dim dcFormatString As DataColumn = New DataColumn(columnName, GetType(String))
167+
tbl.Rows.Clear()
168+
Dim columns As DataColumnCollection = tbl.Columns
169+
If columns.Contains(columnName) = False Then
170+
tbl.Columns.Add(dcFormatString)
171+
End If
172+
173+
Using da = New SqlCeDataAdapter(sql, Connection())
174+
da.Fill(tbl)
175+
End Using
176+
177+
tbl.DefaultView.Sort = columnName & " asc"
178+
Case DialogResult.No
179+
End Select
180+
End If
181+
End Sub
182+
148183
End Class
149184

150185
End Namespace

VB/Scripts/Ribbon.vb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,22 @@ Namespace Scripts
360360
Select Case control.Id
361361
Case "cboDateFormatReplace"
362362
My.Settings.Table_ColumnDateFormatReplace = text
363+
Data.InsertRecord(Data.DateFormatTable, text)
363364
Exit Select
364365
Case "cboDateFormatFind"
365366
My.Settings.Table_ColumnDateFormatFind = text
367+
Data.InsertRecord(Data.DateFormatTable, text)
366368
Exit Select
367369
Case "cboTableAlias"
368370
My.Settings.Table_ColumnTableAlias = text
371+
Data.InsertRecord(Data.TableAliasTable, text)
369372
Exit Select
370373
End Select
374+
371375
Catch ex As Exception
372376
ErrorHandler.DisplayMessage(ex)
373377
End Try
378+
374379
End Sub
375380

376381
Public Function GetText(control As Office.IRibbonControl) As String

0 commit comments

Comments
 (0)