Click here to Skip to main content
15,868,162 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i try to show documents with specidic department id like when hr admin login then he/she able to view only hr documents
i done with thissp and code

sp

SQL
create procedure [dbo].[dddddd]
@userid int
as                    
SELECT  di.DocID, 
        di.DocName, 
        di.Uploadfile, 
        dt.DocType,
        d.DepType, 
        at.ApproveType
FROM    DocumentInfo di
    JOIN
        DocType dt ON dt.DocTypeID = di.DocTypeID
    JOIN 
        Department d ON d.DepID = di.DepID 
        
                      
           join
        Userss ON d.DepID = dbo.Userss.DepID AND di.DocID = dbo.Userss.DocID

    LEFT OUTER JOIN
        Approval a ON a.DocID = di.DocID
    JOIN
        ApproveType at ON at.ApproveID = ISNULL(a.Approveid, 3) 
        
        where  Userss.USERID=@userid    



i create a function
C#
public DataTable getdocall1(int userid)
       {
           //return db.ExecuteDataSet("dddddd").Tables[0];
           string connectionString = @"Database=DMSFYPP;Server=LENOVO-PC\SQLEXPRESS;Integrated Security=True";
           using (SqlConnection connection = new SqlConnection(connectionString))
           {
               SqlCommand command = new SqlCommand("dddddd", connection);
               command.CommandType = System.Data.CommandType.StoredProcedure;
               command.Parameters.AddWithValue("@userid", userid);

               connection.Open();

               DataTable dtResult = new DataTable();
               SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command);
               sqlDataAdapter.Fill(dtResult);

               return dtResult;
           }
       }


then i call this in page load
C#
protected void Page_Load(object sender, EventArgs e)
       {
           GridView1.DataSource = dwww.getdocall1(Convert.ToInt32(Session["UserID"]));
           GridView1.DataBind();
       }



but when i debug the code ..code works fine but gridview not display in form...

where is the problem
Posted
Comments
Richard C Bishop 21-Oct-13 15:24pm    
So the code does not work fine. Where does it fail when you are debugging?
Ranjan.D 21-Oct-13 15:49pm    
Put a debug in line return dtResult; and see whether the data table is filled with some records.
TrushnaK 22-Oct-13 1:29am    
Have you chacked your dataset dtResult having records before returning....
member 8888995 22-Oct-13 1:46am    
Hi Ayesha ,
Set breakpoint at line 'return dtResult;'
Check whether table is filled or not.
Also execute select statement in procedure by providing valid value for '@userid' at SQL-Server end i.e. in SQL Server Management Studio.
Nandakishore G N 22-Oct-13 9:42am    
if there are records in database and records in datatable then check whether attribute of gridview autogeneratecolumns is set to false if yes make it true and try again

1 solution

There are few things that you can look after.

At first run the stored Procedure with the expected userID in SQL query editor and see if you are getting the desired output or not.

Put Your Connection String in Web Config file and then put a debugger at your function which is returning the datatable and another at the gridview binding the datasource.

and write your gridview binding into
C#
if(!ispostback)
{
GridView1.DataSource = dwww.getdocall1(Convert.ToInt32(Session["UserID"]));
GridView1.DataBind();
}


on your page load

and (I think just try) It should be---
C#
GridView1.DataSource = dtResult


Hope this helps
 
Share this answer
 
Comments
Diya Ayesa 22-Oct-13 14:14pm    
when i try this it shows me error

The name 'dtResult' does not exist in the current context
VICK 23-Oct-13 3:35am    
Use the following..
Datatable resultfinal = new Datatable();
resultfinal = (Datatable)dwww.getdocall1(Convert.ToInt32(Session["UserID"]));


and than bind this datatable with your gridview.

Gridview1.DataSource = resultfinal;
Gridview1.DataBind();

Hope it will help :)

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