Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to retrieve the values from a SP

Posted on 2006-05-23
3
Medium Priority
?
190 Views
Last Modified: 2010-04-23
Hi Experts,

I have a simple Sp that I want to fill a datagridview with, but unfortunately I'm not to good with SP myself.

Here is the SP:

CREATE PROCEDURE [ichanneluser].[test3]

@BrukerID nvarchar(50)
AS

SELECT     jpst_Main.ID, jpst_Main.Heading, jpst_Main.Body, jpst_Main.OpprettetAv, jpst_Main.OpprettetDato, jpst_Main.Rute, jpst_Main.Avdeling,
                      jpst_Detail.BrukerID
FROM         jpst_Main INNER JOIN
                      jpst_Detail ON jpst_Main.ID = jpst_Detail.ID
WHERE     (jpst_Detail.BrukerID = @BrukerID)
GO


Here is the vb code

                Dim sqlConn As New SqlClient.SqlConnection
                sqlConn.ConnectionString = getConnection2()
                sqlConn.Open()
                Try

It is here I would like the datagridview called "dg1_1" to be filled vith the results from the SP.


0
Comment
Question by:jonastovsen
  • 2
3 Comments
 
LVL 6

Expert Comment

by:SandeepRR
ID: 16742851
Hi

first create a sql command with type as stored proc and the textas the SP's name

then create a dataadpter and assign the commad as the selectcommand for the dataadpter(and need not to open the connection expicitly)

and then create a dataset and then fill the dataset with dataadpters fill command

and assing that ds as datasourse for datagridview and call datagridview's databind method

SandeepRR

and
0
 
LVL 6

Accepted Solution

by:
SandeepRR earned 2000 total points
ID: 16742897
example

private SqlConnection conn = new SqlConnection();
private SqlCommand cmd = new SqlCommand();
private SqlDataAdapter da = new SqlDataAdapter();
DataSet ds;


conn.ConnectionString = "ConnectionString";
cmd.CommandText = "Sp name";
cmd.CommandType = StoredProcedure;
cmd.Connection = conn;
------------add the parameter to the command-------imp step
SqlParameter sSearchString = new SqlParameter();
                        sSearchString.ParameterName = "@BrukerID";
                        sSearchString.Value = txtSearchString.Text;----source of value
                        sSearchString.SqlDbType = SqlDbType.VarChar;
                        sSearchString.Size = 1000;
                        cmd.Parameters.Add(sSearchString);

da.SelectCommand = cmd;
da.Fill(ds);
dgSearchResult.DataSource = ds;
dgSearchResult.DataBind();


SandeepRR

                        
0
 

Author Comment

by:jonastovsen
ID: 16743668

Thank you SandeepRR.

You just saved my day!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

581 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