Solved

Get value into textbox from sproc

Posted on 2013-07-01
3
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 81

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 36

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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