Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Display results in Textboxes from a stored procedure.

Posted on 2006-07-07
3
Medium Priority
?
224 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses

927 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