Solved

Get value into textbox from sproc

Posted on 2013-07-01
3
265 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 80

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 150 total points
ID: 39292273
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
ID: 39292314
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
ID: 39297166
>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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 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