Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class home : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter adp;
    DataSet ds;

    void connect()
    {
        con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Abhik\Documents\Visual Studio 2010\WebSites\XP\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
        con.Open();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        connect();
        adp = new SqlDataAdapter("select * from user_info where u_mail='"+Session["id"].ToString()+"'", con);
        ds = new DataSet();
        adp.Fill(ds);
        Label1.Text = ds.Tables[0].Rows[0][0].ToString();
        Label2.Text = ds.Tables[0].Rows[0][1].ToString();
        Label3.Text = ds.Tables[0].Rows[0][3].ToString();
        Label4.Text = ds.Tables[0].Rows[0][5].ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("signin.aspx");
    }
}


error in
Line 26: adp = new SqlDataAdapter("select * from user_info where u_mail='"+Session["id"].ToString()+"'", con);
Posted
v2
Comments
Kornfeld Eliyahu Peter 27-Apr-14 9:54am    
First of all - do not use string concatenation to create your SQL query. It's extremely dangerous. See here more about:http://en.wikipedia.org/wiki/SQL_injection.
And my question is: where you set Session["id"]'s value? As obviously that one is null!!!
Nitij 27-Apr-14 13:22pm    
Make sure your object is not null, you can use a null check for that. By the way, your data access code does not seem good. Use a wrapper class or even better a separate project to access the database.

debug and check which object is null.

for example when you call ToString method of Session["id"], if that is null you will get this exception. you can add null check before calling tostring method to avoid this exception. but you need to find why it was null! have you forgot to set that session value?
 
Share this answer
 
v2
Agree with Damith Weerasinghe6K

Dear...Member 10778019312 .. You must use the debugger techniques.

But... one more thing I would like to add is that ... be sure that you are keeping the Connection to your database ONLY for time it required, don't keep it open if there is no need of it after fetching the "SESSION_ID" from particular table.



Happy Programming...:-)
 
Share this answer
 

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