Solved

Get value into textbox from sproc

Posted on 2013-07-01
3
262 Views
Last Modified: 2013-07-03
I am executing a stored procedure in which the dataset that is returned is only 1 row/column. I want to put that value into a textbox. The textbox does not have data binding. How do I get that value into it?
Private Sub GetCostCenter()
    Dim myCommand5 As New SqlCommand("Manager_Select_CostCenter", connection)
     myCommand5.CommandType = CommandType.StoredProcedure
     Dim myDA5 As New SqlDataAdapter
     myDA5.SelectCommand = myCommand5
     Dim dsCostCenter As New DataSet
     myDA5.Fill(dsCostCenter)
     txtCostCenter.Text = dsCostCenter `???
End Sub

Open in new window

0
Comment
Question by:allelopath
3 Comments
 
LVL 78

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 150 total points
Comment Utility
as long as it returns a string
myDA5.Fill(dsCostCenter)
     txtCostCenter.Text = dsCostCenter

or even
 txtCostCenter.Text= myDA5.Fill(dsCostCenter)
0
 
LVL 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 150 total points
Comment Utility
You do not need SqlDataAdapter  a reader will do the job just fine and quicker:
Private Sub GetCostCenter()
     Dim myCommand5 As New SqlCommand("Manager_Select_CostCenter", connection)
     myCommand5.CommandType = CommandType.StoredProcedure
     myCommand5.Parameters.Add("@costcentre", SqlDbType.VarChar)
     myCommand5.Parameters("@costcentre").Direction = ParameterDirection.Output
     Dim sqlReader As SqlDataReader = myCommand5..ExecuteReader()
     sqlReader.Close()
     txtCostCenter.Text = myCommand5.Parameters("@costcentre").Value)
End Sub

Open in new window

Asumption: Stored procedure returns a string parameter called costcentre.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 200 total points
Comment Utility
>You do not need SqlDataAdapter  a reader will do the job just fine and quicker

You do not need a reader either. A single value can be retrieved using ExecuteScalar method


Private Sub GetCostCenter()
    Dim myCommand5 As New SqlCommand("Manager_Select_CostCenter", connection)
     myCommand5.CommandType = CommandType.StoredProcedure
     txtCostCenter.Text = myCommand5.ExecuteScalar()
End Sub

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now