vb.net调用存储过程简单示例

    Private Function validateClient(ByVal guid As StringAs 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
posted on 2011-09-18 00:19  Konimeter  阅读(1189)  评论(0编辑  收藏  举报