VB常见问题点 1、
字符串和变量的拼接问题: If txtCondition.Text <> "" Then '当查询条件不为空时增加相应的查询条件 ' addition = String.Format(" and {0}='{1}' order by {0} {2}", field, txtCondition.Text.Trim(), order) addition = " and " & field & "=@" & field & " order by " & field & " " & order order = "" & order order = order & "" End If 2、
多行字符串的拼接问题: Dim sqlstr As String = "select custID, custNum as 客户编号,custName as 客户名称,custLink as 联系人,phone as 联系电话," & _ "address as 公司地址,custaddress as 客户住址,email as 邮箱,recorduser as 记录人,recorddate as 记录时间,updateuser as 更新人," & _ "updatedate
as 更新时间,custtype as 客户类型,currnum as 交易币别 from customer_test where 1=1
" 3、
时间格式转换问题: If IsDate(cfg.Rows(cfg.Row).Item(9).ToString()) Then recorddate = Format(CDate(cfg.Rows(cfg.RowSel).Item(9).ToString()), "yyyy-MM-dd HH:mm:ss") End If 转换数据类型,此处字符串为时间数据类型所以采用CDate()进行转化。其中"yyyy-MM-dd
HH:mm:ss"为转化之后的数据格式。月为大写M,24小时制为大写H。 4、
Sql语句中的单引号的处理问题: 5、 如何判断文本框中输入的是汉字、字母、数字?(此例题只判断字母和数字,没有处理汉字啊) Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Dim i As Integer Dim a As Integer If TextBox1.Text.Length > 0 Then For i = 1 To TextBox1.Text.Length a = Asc(Mid(TextBox1.Text, i, 1)) Select Case a Case Is < 48, Is > 57 '数字0~9 Select Case a Case Is < 65, 91 To 96, Is > 122 'A_Z a_z MsgBox("非法字符") TextBox1.Text = TextBox1.Text.Remove(i - 1, 1) End Select End Select Next End If End Sub 6、
繁简转化 7、
窗体之间的传值方式 Private Sub tsmiSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmiSearch.Click Dim searchForm As SearchForm = New SearchForm(cfg, Me) '此處實例化的過程中傳遞一個flexGrid控件和主窗体本身 searchForm.ShowDialog() End Sub Dim mForm As System.Windows.Forms.Form '申明一个Form控件 Public Sub New(ByVal grid As C1.Win.C1FlexGrid.C1FlexGrid, ByVal mainForm As System.Windows.Forms.Form) ' This call is required by the Windows Form Designer. InitializeComponent() vsgrid = grid '把主窗体和子窗体的flexgrid联系起来 mForm = mainForm '把主窗体和子窗体的form联系起来 ' Add any initialization after the InitializeComponent() call. End Sub 8、 |
|