Private Function validateClient(ByVal guid As String) As Integer
Dim result As Integer = 0
Try
'读client
Dim client As SqlDataReader
Dim connStr As String = ConfigurationManager.ConnectionStrings("wz").ConnectionString
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand("redlim_client_getdetailbyguid", conn)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
.Add(New SqlClient.SqlParameter("@clientguid", guid))
End With
conn.Open()
client = cmd.ExecuteReader
If Not client Is Nothing AndAlso client.HasRows Then
client.Read()
result = Integer.Parse(client("redlimClientState")) '获取client的状态
client.Close()
Else
'无client,新建client
client.Close()
cmd = New SqlCommand("redlim_client_create", conn)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
.Add(New SqlClient.SqlParameter("@clientguid", guid))
End With
cmd.ExecuteNonQuery()
End If
Catch ex As Exception
End Try
Return result
End Function
Dim result As Integer = 0
Try
'读client
Dim client As SqlDataReader
Dim connStr As String = ConfigurationManager.ConnectionStrings("wz").ConnectionString
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand("redlim_client_getdetailbyguid", conn)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
.Add(New SqlClient.SqlParameter("@clientguid", guid))
End With
conn.Open()
client = cmd.ExecuteReader
If Not client Is Nothing AndAlso client.HasRows Then
client.Read()
result = Integer.Parse(client("redlimClientState")) '获取client的状态
client.Close()
Else
'无client,新建client
client.Close()
cmd = New SqlCommand("redlim_client_create", conn)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
.Add(New SqlClient.SqlParameter("@clientguid", guid))
End With
cmd.ExecuteNonQuery()
End If
Catch ex As Exception
End Try
Return result
End Function
本文介绍了一个用于验证客户端状态的私有函数。该函数通过调用存储过程读取数据库中客户端的状态信息,若不存在则创建新的记录。
792

被折叠的 条评论
为什么被折叠?



