|  | 
	                
  
    |  |  
    | 
        
        ขอความช่วยเหลือคับ ในการดัก Exception  (VB 2008 + Ms sql server 2005)     |  
    |  |  
 
              
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ใช้ regular expresstion 
 Code (VB.NET)
 
 Dim RegPatterm As String = "^[ท|ม]{1}+\w{1}+\s+\d{1,}"
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-13 10:35:51 | By :
                            tungman |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบคุณคับ แต่ งง คับ พี่ช่วย ละเอียดกว่านี้ได้ป่าวคับ ขอบคุณคับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-13 11:35:54 | By :
                            404Not Found |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (VB.NET) 
 Protected Function TungmanCheck(strCheck As String) As Boolean
	Dim RegPatterm As String = "^[ท|ม]{1}+\w{1}+\s+\d{1,4}"
	Dim Rgx As New System.Text.RegularExpressions.Regex(PokedexStartPattern)
	Return If((Rgx.Match(strCheck) IsNot Nothing), True, False)
End Function
เวลาใช้
 
 Code (VB.NET)
 
 If TungmanCheck(txtLicen.Text) Then
    MessageBox.Show("OK")
Else
    MessageBox.Show("Incorrent format.")
End If
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-13 15:15:24 | By :
                            tungman |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | โค๊ตผมเป้นแบบนี้คับ 
 Private Sub bntCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntCheck.Click
 Dim licen As String = txtLicen.Text
 Dim objCmd As New SqlCommand
 Dim strConn As String
 Dim objReader As SqlDataReader
 
 
 
 strConn = "Data Source=.\SQLEXPRESS;Initial Catalog=TblUser;Integrated Security=True"
 
 Dim Conn As New SqlConnection(strConn)
 Conn.Open()
 
 objCmd.CommandType = CommandType.Text
 objCmd.CommandText = "select * from [dbo].[Car] where license='" & licen & "'"
 objCmd.Connection = Conn
 objCmd.CommandTimeout = 0
 
 objReader = objCmd.ExecuteReader
 
 
 
 
 
 If licen = "" Then
 MessageBox.Show("กรุณากรอก หมายเลขทะเบียนรถ")
 
 ElseIf objReader.HasRows Then
 MessageBox.Show("หมายเลขทะเบียนนี้ไม่สามารถใช้ได้")
 Else
 MessageBox.Show("หมายเลขทะเบียนนี้สามารถใช้ได้")
 btnSave.Visible = True
 End If
 
 Conn.Close()
 
 
 
 
 End Sub
 
 
 ตรงที่พี่บอกมันก็ Error คับ
 
 
 
 
 
 
 
 
  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-13 15:54:10 | By :
                            404Not Found |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-13 15:54:42 | By :
                            404Not Found |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | โทดๆ พอดีหลับตาเขียน 
 Code (VB.NET)
 
 Protected Function TungmanCheck(strCheck As String) As Boolean
	Dim RegPatterm As String = "^[ท|ม]{1}+\w{1}+\s+\d{1,4}"
	Dim Rgx As New System.Text.RegularExpressions.Regex(RegPatterm)
	Return If((Rgx.Match(strCheck) IsNot Nothing), True, False)
End Function
 ว่าแต่เรียกใช้ function ไม่เป็นรึเปล่า แล้วก็ไม่ต้อง spam นะมันรกตา เห็นตั้งไป 3 กระทู้แล้ว
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-13 16:40:41 | By :
                            tungman |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | "^[ท|ม]{1}+\w{1}+\s+\d{1,4}" 
 อธิบาย เพิ่มเติมได้ไหมครับว่า สัญลักษณ์อะไรคือะไร
 
 ขอบคุณครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-13 22:36:03 | By :
                            Knight |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | จับ pattern ของทะเบียนรถ 
 กำหนดให้ตัวแรกต้องเริ่มต้นด้วย ท หรือ ม เท่านั้น
 
 จากนั้นตามด้วยตัวอักษรหรือตัวเลขอะไรก็ได้ 1 ตัว
 
 ตามด้วย space 1 ตัว
 
 จากนั้นก็เป็นตัวเลขอย่างน้อย 1-4 ตัว
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-08-13 22:38:37 | By :
                            tungman |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Dim fileName As String = dirquiz + "\Program Files\QuizP4" 
 MessageBox.Show(fileName)
 
 
 Dim Rights As FileSystemRights
 
 Dim Account As String = "Users"
 
 Rights = FileSystemRights.FullControl
 
 'set on dir itself
 Dim AccessRule As New FileSystemAccessRule(Account, Rights, AccessControlType.Allow, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)
 
 
 Dim dInfo As New DirectoryInfo(fileName)
 Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
 dSecurity.ModifyAccessRule(AccessControlModification.Set, AccessRule, True)
 'Always allow objects to inherit on a directory
 
 Dim iFlags As New InheritanceFlags()
 iFlags = InheritanceFlags.ContainerInherit + InheritanceFlags.ObjectInherit
 
 'Add Access rule for the inheritance
 Dim AccessRule2 As New FileSystemAccessRule(Account, Rights, iFlags, PropagationFlags.InheritOnly, AccessControlType.Allow)
 dSecurity.ModifyAccessRule(AccessControlModification.Add, AccessRule2, True)
 
 dInfo.SetAccessControl(dSecurity)
 เมื่อ รัน บน windows7 แล้วผิดพลาดตรงคำสั่งนี้   สุดท้ายนี้  dInfo.SetAccessControl(dSecurity)
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2010-11-09 17:38:35 | By :
                            สุพจน์ |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |