2015-04-17 17 views
-4

我想讓自動編號,並得到了下面的錯誤 請幫我解決它。需要幫助:從字符串「RS201504170001」轉換爲類型'雙'無效

下面是我的代碼:

Sub noresep() 
    Call Koneksi() 
    Dim nors As String = "Select * from tb_resep where no_resep in (Select max(no_resep) from tb_resep)" 
    cmd = New MySqlCommand(nors, db) 
    dr = cmd.ExecuteReader 
    dr.Read() 
    If Not dr.HasRows Then 
     txt_noresep.Text = "RS" + Format(Now, "yyyyMMdd") + "0001" 
    Else 
     If Microsoft.VisualBasic.Mid(CStr(dr.Item("no_resep")), 3, 8) <> Format(Now, "yyyyMMdd") Then 
      txt_noresep.Text = "RS" + Format(Now, "yyyyMMdd") + "0001" 
     Else 
      txt_noresep.Text = CDbl(dr.Item("no_resep")) + 1 'Error in this line 
     End If 
+0

我得到錯誤:從字符串「RS201504170001」轉換爲鍵入'雙'無效。 –

+2

「自動編號」不提供關於您的代碼試圖執行的任何信息。在不知道代碼應該達到什麼目的的情況下,任何人都無法就修復提出建議。 – Unihedron

回答

0

那麼,你就不能轉換字母數字數據類型,刪除「RS」的部分從字符串。

txt_noresep.Text = CDbl(dr.Item("no_resep").ToString.TrimStart({"R"c, "S"c})).ToString 
+0

感謝您的解決方案..它的解決.. –

+0

@Glenn Maramis高興地幫助,但如果它的解決,那麼請標記答案爲接受,歡迎來到StackOverflow,但閱讀規則。 – ElektroStudios

+0

感謝您的評論,無論如何標記答案?對不起.. –

相關問題