Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
datalistpage.aspx
C#
protected void dlProfile_ItemCommand(object source, DataListCommandEventArgs e)
   {
       if (e.CommandName == "Details")
       {
           string FirstName = Convert.ToString(e.CommandArgument);

           Response.Redirect("ViewDetails.aspx?@UserId=" +ID);



       }
   }



ViewDetails.aspx
C#
protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_JoinRegistration";
        cmd.Connection = con;
        con.Open();

        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        dlProfile.DataSource = dt;
        dlProfile.DataBind();

        cmd.Dispose();
        con.Close();  

    }


here is my code..problem is m retrieving all tables details..but i want to retriev selected tables data in datalist..can anyone help me..
Posted
Updated 13-Dec-11 19:18pm
v2

You are getting data from a stored procdure.
The code for this procdure is not provided here so I don't know what code runs.

However, you basically need to modify the stored procedure to get only those columns you are interested in.
That would be the easiest approach to solve this problem.
 
Share this answer
 
Comments
ythisbug 14-Dec-11 1:30am    
oh ok..withot using stored procedure how can i retreive??any idea..
ythisbug 14-Dec-11 1:31am    
ALTER PROCEDURE [dbo].[usp_JoinRegistration]
AS


BEGIN
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT Registration.FirstName,Registration.MiddleName,Registration.LastName,Registration.DateOfBirth,Registration.Gender,Registration.Email,Registration.Occupation,Registration.State,Registration.City,Registration.Nationality,Registration2.UserId,Registration2.Address,Registration2.Company,Registration2.Relationship,Registration2.DateOfJoin,Registration2.Place
from Registration,Registration2
where Registration.ID=Registration2.ID
END

this is stored procedure ..any changes should i make..??
Abhinav S 14-Dec-11 2:17am    
Just choose those columns that you need in this stored procedure. Remove the others.
Of course, make sure this SP is not used anywhere else.
ythisbug 14-Dec-11 4:03am    
ALTER PROCEDURE [dbo].[ups_JoinRegistration2]
@UserId int

AS


BEGIN
SET NOCOUNT ON;

SELECT * from [Registration2] where UserId=@UserId

END

this much i declared in storedprocedure..wat should i make changes??
Hi,

Correct your code as example:
C#
string studentId = "1234";
Response.Redirect("ViewDetails.aspx?en=" + studentId);



in your ViewDetails.aspx code behind:

C#
if (!IsPostBack)
{
    string id = Request.QueryString["en"].ToString();
    // Pass the id in your StoredProcedure
    // Some code here?...
    SqlCommand cmd = new SqlCommand("usp_JoinRegistration", conn)
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("@UserID", SqlDbType.NVarChar).Value = id ;
    // Some code here?...
}



Check your Store proc. usp_JoinRegistration should have a
UserID parameter to pass in order to filter the condition...

Please vote if could help so that others may consider as an answer...

Regards,
 
Share this answer
 
Comments
ythisbug 14-Dec-11 3:37am    
System.Data.SqlClient.SqlException: Procedure or Function 'ups_JoinRegistration2' expects parameter '@UserId', which was not supplied.

after all this m getting this error..
Al Moje 14-Dec-11 4:59am    
ALTER PROCEDURE [dbo].[ups_JoinRegistration2]
@UserId int
AS
BEGIN
SET NOCOUNT ON;
SELECT * from [Registration2] where UserId=@UserId
END


the above code is your store proc.
You must:
1. Target the exact store proc 'ups_JoinRegistration2'
2. You must know the type of your parameter ( change code)

int id = Convert.ToInt32(Request.QueryString["en"].ToString());

cmd.Parameters.Add("@UserID", SqlDbType.Int).Value = id ;
ythisbug 14-Dec-11 5:19am    
k thaks

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