2017-03-16 26 views
-1

您看到我國的聯繫電話號碼僅限於7位或11位數字。但我似乎無法得到我Len的工作方式。如何使用TextBox長度做聯絡號碼限制?

這是我的代碼:

If Len(TextBox5.Text) <> 11 Or Len(TextBox5.Text) <> 7 Then 
     MsgBox("Invalid Contact Number") 
    Else 
     MsgBox("Contact Number Accepted") 
    End If 
+0

使用'using'語句實現'IDisposable'。只要您喜歡,您可以在其中包含儘可能多的嵌套數據讀取器。請記住明確命名它們。 –

+0

你能告訴我一個使用我的代碼的例子嗎? – Primitive

+0

@DanielShillcock我不是家人,說實話 – Primitive

回答

0

這是罰款有嵌套數據的讀者,但我建議你使用Using聲明這會爲您(或其他任何實現IDisposable)處置您的DataReader的。

請參閱下面的一般前提。

Using firstDataReader As New MySqlDataReader() 
    firstDataReader.ExecuteReader("SELECT TOP 1 * FROM TABLE") 
    If (firstDataReader.Read) Then 
     using secondDataReader as New MySqlDataReader() 
      secondDataReader.ExecuterReader("SELECT TOP 1 * FROM ANOTHER_TABLE") 
      If (secondDataReader.Read) Then 
       'Do Stuff 
      End If 
     End Using 
    End If 
End Using 

正如你所看到的,你自己並不需要Dispose()對象。 .NET CLR將在退出Using聲明時處理它們。

+0

我上次檢查MySql不允許兩個打開的數據讀取器在同一個連接上。 – Steve

+0

這很可能是真的,我從來沒有使用MySql datareaders ... –