Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a problem to fill a grid view according to the given parameter.
The stored procedure that I made is as following:
SQL
CREATE PROCEDURE [dbo].[procNAME]
(
@ID_Personi int
)
AS
BEGIN
SELECT SHKOLLA.ID_Shkolla, SHKOLLA.ShkollaEmertimi, SHKOLLA.VitiAkademik, SHKOLLA.ID_Personi, SHKOLLA.ID_Komuna 
       , LLOJI_SHKOLLES.LlojiShkolles FROM SHKOLLA
inner join LLOJI_SHKOLLES on LLOJI_SHKOLLES.ID_Shkolla=SHKOLLA.ID_Shkolla 
 where SHKOLLA.ID_Personi = @ID_Personi

END


My problem is: how to send this parameter to database from grid view population. I populate the grid view with stored procedure.
I need a c# code.
P.S. This ID_Personi exists as a Session on a page load.
Thank you in advance for your reply.
Posted
Comments
ZurdoDev 29-Oct-15 10:34am    
There are tons of examples of how to use gridviews. You can use a SelectParameter on your datasource, for example.
sudevsu 29-Oct-15 11:42am    
What did you try so far? what was the error you got

 
Share this answer
 
I solved the problem with the following code:
C#
public void ShowGV()
        {
            SqlConnection sqlConn = new SqlConnection(StringKoneksioni.Stringu);
            using (sqlConn)
            {
                SqlCommand sqlCmd = new SqlCommand("procNAME", sqlConn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
              

               /// The problem was here, I didn't know how to put those two following rows
                sqlCmd.Parameters.Add(new SqlParameter("@ID_Person", SqlDbType.Int));
                sqlCmd.Parameters["@ID_Personi"].Value = Session["ID_Person"];
                sqlConn.Open();
                SqlDataReader reader = sqlCmd.ExecuteReader();
                gvName.DataSource = reader;
                gvName.DataBind();
                sqlConn.Close();
            }
           

        }


Once again tank you for your reply.
Cheers.
 
Share this answer
 
v2
Comments
Maciej Los 29-Oct-15 16:45pm    
The best "thank you" is when you accept valuable answer(s) as a solution and vote-up the answer(s).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900