最近我在一个小的VB.Net程序中遇到了问题。该程序正在使用OleDb
来控制我们用来跟踪工作中的每周检查的Excel电子表格。 OleDb
部分工作正常,但我添加了几个RegEx
语句来验证一些输入,其中一个语句不起作用。 RegEx
定义为
Private ReadOnly rgxTM As New Regex("^[T][M][ ]\d{4}$")`
并评估为
If Not rgxTM.IsMatch(tm) Then
MessageBox.Show("The tape measure number you entered is invalid.", "Invalid Tape Measure", MessageBoxButtons.OK, MessageBoxIcon.Error)
Tb.Text = ""
Exit Sub
End If
tm
定义为tm = newForm.tmTb.Text.ToUpper
比较RegEx
后,它会OleDb.OleDbCommand
更新CommandText
,清除Parameters
并为新CommandText
设置OleDb.OleDbConnection
,打开UPDATE
,执行MessageBox.Show
语句,然后关闭连接。这里的所有内容都有效,我可以看到新的值正在实时输入到Excel电子表格中。
起初我认为这些陈述从未被输入,但是看到电子表格中的数据更新证明它正在通过这一部分的嵌套。我放置了rgxTM.IsMatch(tm)
并传递了MessageBox
的对话框,cmd.ExecuteNonQuery()
永远不会显示出来。此外,如果我在此嵌套部分设置了任何断点,则断点永远不会被击中,即使我在明确更新电子表格的Option Explicit On
Imports System.Data.OleDb
Imports System.Text.RegularExpressions
Private ReadOnly conStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"""
Private ReadOnly con As New OleDbConnection With {
.ConnectionString = conStr
}
Private ReadOnly rgxTM As New Regex("^[T][M][ ]\d{4}$")
Private response As String
Dim cmdStr As String = "SELECT name, [Tape Measure Number], [Date Calibrated], [New Tape Measure Number] FROM [TAPE MEASURE LIST$] WHERE [Employee Number] = @gage"
Dim cmd As New OleDbCommand With {
.CommandText = cmdStr,
.Connection = con
}
Dim newForm As New NewForm("Please scan your new tape measure.")
response = newForm.ShowDialog()
If response <> vbOK Then
Tb.Text = ""
Exit Sub
Else
tm = newForm.tmTb.Text.ToUpper
MessageBox.Show(rgxTM.IsMatch(tm))
If Not rgxTM.IsMatch(tm) Then
MessageBox.Show("The tape measure number you entered is invalid.", "Invalid Tape Measure", MessageBoxButtons.OK, MessageBoxIcon.Error)
Tb.Text = ""
Exit Sub
End If
cmd.CommandText = "UPDATE [TAPE MEASURE LIST$] SET [NEW TAPE MEASURE NUMBER] = @tm, [DATE OF CHANGE] = @date WHERE [EMPLOYEE NUMBER] = @empnum"
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@tm", tm)
cmd.Parameters.AddWithValue("@date", DateTime.Now.ToShortDateString)
cmd.Parameters.AddWithValue("@empnum", gage)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Tb.Text = ""
End If
上设置断点也是如此。
我已经检查了我的调试配置(Debug,Any CPU),编译配置(我已经尝试了Debug和Release,每个都选择了Any CPU和x86),选中并取消选中“要求源文件与原始版本完全匹配“据我所知,自从2017年首次启动以来,我没有改变任何重大的实际设置。
代码段
else
忽略在else
语句中输入的任何断点;我使用的任何其他断点都正常命中。我知道自UPDATE
执行以来它正在输入with detect_first_in_seq$ as (
select X.*,
case when lnnvl(lag(X.cdr_id) over (partition by num order by cdr_id) = X.cdr_id-1) then X.cdr_id end as is_first_cdr_id_in_seq
from tmp_cdr_gaps X
),
copy_first_in_seq$ as (
select X.*,
last_value(is_first_cdr_id_in_seq ignore nulls) over (partition by num order by cdr_id) as first_cdr_id_in_seq
from detect_first_in_seq$ X
)
select
X.*,
row_number() over (partition by num, first_cdr_id_in_seq order by cdr_id) as status_sequence
from copy_first_in_seq$ X
;
语句。
我在Windows 7 Professional 64上使用Office 2010和Visual Studio 2017运行此功能。