Private Sub btnGetTopic_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnGetTopic.Click Try Dim ID As Integer = Int32.Parse(txQueryID.Text) GetItem(ID) @# 进行数据库调用 txID.Text = txQueryID.Text txTitle.Text = mTitle txDescription.Text = mDescription lbStatus.Text = "suclearcase/" target="_blank" >ccess!" Catch ex As Exception lbStatus.Text = ex.Message End Try End Sub |
Private Sub GetItem(ByVal ID As Integer) Try pr = New SqlParameter("RETURN_VALUE", SqlDbType.Int) pr.Direction = ParameterDirection.ReturnValue Dim pTitle As SqlParameter = New SqlParameter With pTitle .Direction = ParameterDirection.Output .DbType = DbType.String .ParameterName = "@Title" .Size = 30 End With Dim pDescription As SqlParameter = New SqlParameter With pDescription .Direction = ParameterDirection.Output .DbType = DbType.String .ParameterName = "@Description" .Size = 500 End With cd = New SqlCommand With cd .CommandText = "TopicsGetItem" .CommandType = CommandType.StoredProcedure .Parameters.Add(New SqlParameter("@AdminCode", "adm")) .Parameters.Add(New SqlParameter("@ID", ID)) .Parameters.Add(pTitle) .Parameters.Add(pDescription) .Parameters.Add(pr) .Connection = cn .Connection.Open() .ExecuteNonQuery() .Connection.Close() End With @# 检查返回代码 If Not pr.Value Is Nothing Then Select Case Int32.Parse(pr.Value) Case 100 : Throw New ApplicationException("Access violation") Case 101 : Throw New ApplicationException("Invalid ID") End Select End If @# 设置返回值 mTitle = pTitle.Value.ToString() mDescription = pDescription.Value.ToString() Catch ex As Exception Throw New Exception(ex.Message, ex) End Try End Sub |