Solved

Get value into textbox from sproc

Posted on 2013-07-01
3
264 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 79

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

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