Solved

Display results in Textboxes from a stored procedure.

Posted on 2006-07-07
3
215 Views
Last Modified: 2010-04-23

I have a stored procedure that looks like this:

CREATE PROCEDURE [ichanneluser].[jpst_test]
@ID int

AS

SELECT     KundeNavn, Avdeling, Adresse
FROM         dbo.opp_Kunde
WHERE     (ID = @ID)
GO


How can I display the results in different textboxes?

Here is how I connect:

        '-----------------------------------
        Dim sqlConn As New SqlClient.SqlConnection
        sqlConn.ConnectionString = getConnection2()
        sqlConn.Open()
        Dim cmd As New SqlClient.SqlCommand
        Dim DA As New SqlClient.SqlDataAdapter
        Dim ds As New DataSet
        '-----------------------------------

        cmd.CommandText = "jpst_test"
        cmd.Parameters.Add("@ID", SqlDbType.NChar, 1000).Value = "1"

0
Comment
Question by:jonastovsen
3 Comments
 
LVL 6

Accepted Solution

by:
cubixSoftware earned 500 total points
Comment Utility

        cmd.Parameters.Add("@ID", SqlDbType.NChar, 1000).Value = "1"
        da.selectcommand = cmd
        da.fill(ds)

        if ds.tables(0).rows.count = 1 then
           dim dr as datarow
           dr = ds.tables(0).rows(0)
           textbox1.text = dr("KundeNavn")
           textbox2.text = dr("Avdeling")    
           textbox3.text = dr("Adresse")
        end if


if any of your values can be null then you can test as follows

If dr.IsNull("Adresse") then
    textbox3.text = nothing
end if


HTH
0
 
LVL 8

Expert Comment

by:Shakti109
Comment Utility

Without seeing more of your code, it appears tha by you defining that "ds as new dataset" you are getting back the values in a dataset. By looking at your stored procedure, it appears you are selecting 3 values.

Going along those lines :

Mytextbox1.text = ds.tables(0).rows(0).item(0)
Mytextbox2.text = ds.tables(0).rows(0).item(1)
Mytextbox3.text = ds.tables(0).rows(0).item(2)


This assumes of course you are getting your values back as this (ds) dataset, have only one table, and are not returning multiple rows.

If you are returning multiple rows, then looping through them using a similar set of statements will suffice.
0
 

Author Comment

by:jonastovsen
Comment Utility
Thanks for your help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

7 Experts available now in Live!

Get 1:1 Help Now