Solved

Display results in Textboxes from a stored procedure.

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
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…

734 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