How to retrieve the values from a SP

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.


jonastovsenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
SandeepRRCommented:
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
 
SandeepRRCommented:
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

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
jonastovsenAuthor Commented:

Thank you SandeepRR.

You just saved my day!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.