Solved

Display results in Textboxes from a stored procedure.

Posted on 2006-07-07
3
216 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

28 Experts available now in Live!

Get 1:1 Help Now