Solved

Display results in Textboxes from a stored procedure.

Posted on 2006-07-07
3
217 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
ID: 17058697

        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
ID: 17058706

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
ID: 17060239
Thanks for your help!
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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 a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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