Hi guyz

I have a problem with page-load event. When i m runing the website on local host it is working fine
but
On putting it to web space there is problem with page load event where on page load it is showing "Object reference not set to an instance of an object. " but on refreshing the page it is working.


plz help me

Hi guyz

I have a problem with page-load event. When i m runing the website on local host it is working fine
but
On putting it to web space there is problem with page load event where on page load it is showing "Object reference not set to an instance of an object. " but on refreshing the page it is working.


plz help me

Pls. post your code

Pls. post your code

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.SessionState;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        string username = Session["username"].ToString();

            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Connectionstring";
            string query = "Select Name, Gender, Dob, Age, Religion, Region, Caste,  from Useraccount where Username =@User";
            SqlCommand cmd1 = new SqlCommand(query, conn);
            cmd1.Connection = conn;

            cmd1.Parameters.AddWithValue("@User", username);
            string query1 = "Select Photo from Useraccount where Username =@user";
            SqlCommand cmd = new SqlCommand(query1, conn);
            cmd.Parameters.AddWithValue("@user", username);
            cmd.Connection = conn;
            conn.Open();
            SqlDataReader d = cmd.ExecuteReader();
            while (d.Read())
            {
                int contentLength = Convert.ToInt32(d.GetBytes(0, 0, null, 0, int.MaxValue));
                byte[] buffer = new byte[contentLength];
                d.GetBytes(0, 0, buffer, 0, contentLength);
                Response.ContentType = "Image";

                MemoryStream ms = new MemoryStream();
                ms.Write(buffer, 0, contentLength);

                Bitmap bit = new Bitmap(ms);
                Response.ContentType = "image/jpeg";
                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

                string filename = "photo";
                img.Save(Server.MapPath(filename), System.Drawing.Imaging.ImageFormat.Jpeg);
                Image1.ImageUrl = "photo";
                Response.ContentType = "image/jpeg";
                //or you can select your imagetype from database or directly write it here

            }
            d.Close();


            SqlDataReader dr = cmd1.ExecuteReader();
            while (dr.Read())
            {

                lname.Text = dr["Name"].ToString();
                Label2.Text = dr["Gender"].ToString();
                Label3.Text = "D-O-B:" + " " + " " + dr["Dob"].ToString();
                Label4.Text = "Age:" + " " + " " + dr["Age"].ToString();
                Label5.Text = dr["Religion"].ToString();
                Label6.Text = "Region:" + " " + " " + dr["Region"].ToString();
                Label7.Text = "Caste:" + " " + " " + dr["Caste"].ToString();
                Label8.Text = dr["Maritalstatus"].ToString();
                Label9.Text = "Gotra:" + " " + " " + dr["Gotra"].ToString();
                Label10.Text = dr["Employmentstatus"].ToString();
                Label11.Text = dr["Workarea"].ToString();
                Label12.Text = "Build:" + " " + " " + dr["Build"].ToString();
            }

            Label14.Text = "Welcome" + " " + " " + " " + " " + lname.Text;
    }
}
}

Its working fine on local host

Hey Guyz

Anyone have solution

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.