更新我完成VB asp.net字符串操作
0
A
回答
1
時,將發佈新的代碼如果您檢查,如果SP有兩個元素或沒有做
If sp.Length = 2 Then
...
End If
和If
塊內,你可以做
Dim track1 as String = sp(0)
Dim track2 as String = sp(1)
1
C#更符合我的喜好,但這是一個粗略的方法,將拆分您的字符串,測試正確數量的元素,然後創建數據庫連接(假定SQL Server BU任何ole db應該工作)並調用你的存儲過程。
Public Sub ProcessSwipe(ByVal value As String)
Dim splitValues() As String
Dim separator As Char = ";"
Dim connectionString As String = String.Empty
Dim storedProcName As String = String.Empty
' Edit these to sane values
connectionString = "Provider=SQLOLEDB;BData Source=localhost;Initial Catalog=msdb;Integrated Security=SSPI;"
storedProcName = "dbo.SaveSwipe"
If String.IsNullOrEmpty(value) Then
MsgBox("No value provided from swipe")
Return
End If
Try
splitValues = value.Split(separator)
If splitValues.Length <> 2 Then
MsgBox(String.Format("Splitting of swipe data did not result in 2 values. Swiped value is {0}", value))
Return
End If
' At this point, we should have an array with 2 elements in it
' Open a connection
Using connection As New OleDb.OleDbConnection(connectionString)
connection.Open()
Using Command As New OleDb.OleDbCommand
Command.CommandText = storedProcName
Command.CommandType = CommandType.StoredProcedure
Command.Connection = connection
' Assumes your proc takes 2 parameters, named swipe1 and swipe2
' Update to sane values
Command.Parameters.AddWithValue("@swipe1", splitValues(0))
Command.Parameters.AddWithValue("@swipe2", splitValues(1))
' Make the actual call to your stored procedure
Command.ExecuteNonQuery()
End Using
End Using
Catch ex As Exception
MsgBox(String.Format("Attempt to split {0} failed. {1}", value, ex))
End Try
End Sub
Sub Main()
Dim shorty As String
Dim works As String
Dim longun As String
Dim nuthin As String
shorty = "%128565?"
works = "%128565?;229584115?"
longun = "%128565?;229584115?%128565?;229584115?"
nuthin = Nothing
ProcessSwipe(shorty)
ProcessSwipe(works)
ProcessSwipe(longun)
ProcessSwipe(nuthin)
End Sub
+0
感謝您的代碼,但是我需要檢索一個或另一個跟蹤代碼,只檢查是否存在2個元素,然後它會做一些事情。我使用vb中的中間函數來獲取我需要的數字,並將它們存儲在2個單獨的變量中,並根據所存在的變量進行調用 – Tim
相關問題
- 1. 字符串操作(ASP.NET MVC)
- 2. 字符串操作
- 3. iphone字符串操作
- 4. 操作字符串內的操作符
- 5. 字符串操作
- 6. 字符串操作
- 7. 字符串操作
- 8. 字符串操作
- 9. 字符串操作
- 10. 字符串操作
- 11. 字符串操作
- 12. 字符串操作
- 13. 字符串操作
- 14. 字符串操作?
- 15. 字符串操作
- 16. 字符串操作
- 17. 字符串操作
- 18. 字符串操作
- 19. 字符串操作
- 20. 字符串操作
- 21. 字符串操作
- 22. 字符串操作
- 23. 操作字符串
- 24. 字符串操作
- 25. 字符串操作
- 26. 字符串操作
- 27. 字符串操作
- 28. 字符串操作
- 29. 字符串操作
- 30. 字符串操作
您的.NET語言將具有比存儲過程更多優雅的處理字符串(拆分,測試等)的工具。 – billinkc