更新我完成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