悬赏园豆:30
[已关闭问题]
关闭于 2008-04-03 08:56
<P>Dim sqlBuilder As New System.Text.StringBuilder<BR> Dim strRes As String = String.Empty<BR> For Each ctrl As Control In Me.Controls<BR> If TypeOf ctrl Is TextBox Then<BR> sqlBuilder.Replace(sqlBuilder.ToString(), Nothing)<BR> sqlBuilder.AppendLine("If Trim(txt{0}ST.Text) <> """" Then")<BR> sqlBuilder.AppendLine("aSql = aSql & "" and {0} ='"" & txt{1}{2}.Text & ""'""")<BR> sqlBuilder.AppendLine("End If")<BR> Dim strFieldName As String = ctrl.Name.Substring(3, ctrl.Name.Length - 3)<BR> strRes &= String.Format(sqlBuilder.ToString, strFieldName)<BR> End If<BR> Next</P>
<P mce_keep="true"> </P>
<P>我的窗体有很多很多的TextBox控件,我想用一个宏来生成供Sql语句用的代码</P>
<P>如下</P>If Trim(txtSample.Text) <> "" Then<BR> aSql = aSql & " and Sample >= '" & txtSample.Text & "'"<BR>End If
<P mce_keep="true">其实我上面的代码就能实现,可是带在调试的时候在即时窗口里粘出来,比较麻烦。<BR>在宏里面能遍历我的Winform或者Webform吗?</P>