Click here to Skip to main content
15,904,155 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questiondisabling the select feature programatically on gridview Pin
bfis1081373-Jan-09 11:52
bfis1081373-Jan-09 11:52 
AnswerRe: disabling the select feature programatically on gridview Pin
moon_stick5-Jan-09 1:29
moon_stick5-Jan-09 1:29 
QuestionBinding data from sql to asp Calender Controle Pin
kimo code3-Jan-09 7:32
kimo code3-Jan-09 7:32 
AnswerRe: Binding data from sql to asp Calender Controle Pin
Abhijit Jana4-Jan-09 0:40
professionalAbhijit Jana4-Jan-09 0:40 
GeneralRe: Binding data from sql to asp Calender Controle Pin
kimo code4-Jan-09 3:16
kimo code4-Jan-09 3:16 
GeneralRe: Binding data from sql to asp Calender Controle Pin
Abhijit Jana4-Jan-09 3:42
professionalAbhijit Jana4-Jan-09 3:42 
GeneralRe: Binding data from sql to asp Calender Controle Pin
kimo code4-Jan-09 4:47
kimo code4-Jan-09 4:47 
Questionwierd null reference exception in asp but not in windows forms Pin
bfis1081373-Jan-09 6:51
bfis1081373-Jan-09 6:51 
I am new. Let's first get that out of the way and even more so my asp/winforms 3 tier project is due tomorrow. Anyways I run the same code in winforms and get no exception, but in asp I do. All the code is in the first 2 tiers. It's really just 3 lines of code that go in asp or winforms.

The exception is as follows
Server Error in '/WebSite' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 21: {
Line 22: //System.Diagnostics.Debugger.Break();
Line 23: conStr = ConfigurationManager.ConnectionStrings[conStrName].ConnectionString;
Line 24: dbType = ConfigurationManager.ConnectionStrings[conStrName].ProviderName;
Line 25:


Source File: C:\prog\finalProject\BookStore\BookStoreDAL\DalClass.cs Line: 23

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
BookStoreDAL.DALClass..ctor(String conStrName) in C:\prog\finalProject\BookStore\BookStoreDAL\DalClass.cs:23
BookStoreBLL.BooksBLL..ctor(String conStr) in C:\prog\finalProject\BookStore\BookStoreBLL\BooksBLL.cs:16
Default2.Page_Load(Object sender, EventArgs e) in c:\prog\finalProject\BookStore\WebSite\allBooks.aspx.cs:20
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436


In asp it looks like this
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 BookStoreBLL;
using System.Collections.Generic;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        BooksBLL bll = new BooksBLL("C");
        Book[] books = bll.allBooks();
        GridView1.DataSource = books;

        
    }
    
}


in winforms it looks like this
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BookStoreBLL;

namespace BookStoreWindowsForms
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            BooksBLL bll = new BooksBLL("C");
            Book[] books = bll.allBooks();
            dataGridView1.DataSource = books;
            
            
        }        
    }
}

I have some business logic that looks like this
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using BookStoreDAL;
using System.Data.Common;

namespace BookStoreBLL
{

    public class BooksBLL
    {
        private DALClass dal;
        public BooksBLL(string conStr)
        {
            dal = new DALClass(conStr);
        }

        public Book[] allBooks()
        {
            string sql = "SELECT * FROM Books";
            List<book> allBooks = new List<book>();
            dal.Open();
            DbDataReader reader = dal.ExecuteReader(sql);
            if (reader != null)
            {
                while (reader.Read())
                {
                    Book book = new Book();
                    book.BookCode = (int)reader["ID"];
                    book.BookName = (string)reader["BookName"];
                    book.Publisher = (string)reader["Publisher"];
                    book.Price = (decimal)reader["price"];
                    book.BooksInStock = (int)reader["AmountInStock"];
                }
                reader.Close();
            }
            dal.Close();


            return allBooks.ToArray();
        }
    }
}</book></book>


And then it goes to some data logic that looks like this
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;


namespace BookStoreDAL
{
    public class DALClass
    {
        private string conStr;
        private DbConnection con;
        private DbCommand com;
        private string dbType;

        public DALClass(string conStrName)
        {
            //System.Diagnostics.Debugger.Break();
            conStr = ConfigurationManager.ConnectionStrings[conStrName].ConnectionString;
            dbType = ConfigurationManager.ConnectionStrings[conStrName].ProviderName;

            if (dbType == "System.Data.SqlClient")
            {
                con = new SqlConnection(conStr);
                com = new SqlCommand();
            }
            else if (dbType == "System.Data.OleDb")
            {
                con = new OleDbConnection(conStr);
                com = new OleDbCommand();
            }
            com.Connection = con;
        }

        public bool Open()
        {
            try
            {
                if (con.State != ConnectionState.Open)
                    con.Open();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public void Close()
        {
            con.Close();
        }

        public DbDataReader ExecuteReader(string sql)
        {
            try
            {
                com.CommandText = sql;
                DbDataReader reader = com.ExecuteReader();
                return reader;
            }
            catch
            {
                return null;
            }
        }

        public bool ExecuteNonQuery(string sql)
        {
            try
            {
                com.CommandText = sql;
                com.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public DbDataReader ExecuteReader(DbParameter[] parameters, string sql)
        {
            try
            {
                com.CommandText = sql;
                com.Parameters.AddRange(parameters);
                DbDataReader reader = com.ExecuteReader();
                com.Parameters.Clear();
                return reader;
            }
            catch
            {
                return null;
            }
        }

        public DbParameter CreateDbParameter(string name, object value)
        {
            DbParameter param = null;
            if (dbType == "System.Data.SqlClient")
                param = new SqlParameter();
            else if (dbType == "System.Data.OleDb")
                param = new OleDbParameter();

            param.ParameterName = name;
            param.Value = value;
            return param;
        }
    }
}


Once again, there are no problems in in winforms and yet it i get this in asp. Any help would be greatly appreciated
AnswerRe: wierd null reference exception in asp but not in windows forms Pin
Colin Angus Mackay3-Jan-09 7:05
Colin Angus Mackay3-Jan-09 7:05 
GeneralRe: wierd null reference exception in asp but not in windows forms Pin
bfis1081373-Jan-09 7:18
bfis1081373-Jan-09 7:18 
QuestionSession timeout problem Pin
nour1233-Jan-09 4:57
nour1233-Jan-09 4:57 
AnswerRe: Session timeout problem Pin
Aman Bhullar3-Jan-09 5:11
Aman Bhullar3-Jan-09 5:11 
GeneralRe: Session timeout problem Pin
N a v a n e e t h3-Jan-09 5:17
N a v a n e e t h3-Jan-09 5:17 
GeneralRe: Session timeout problem Pin
Colin Angus Mackay3-Jan-09 5:28
Colin Angus Mackay3-Jan-09 5:28 
GeneralRe: Session timeout problem Pin
N a v a n e e t h3-Jan-09 5:39
N a v a n e e t h3-Jan-09 5:39 
GeneralRe: Session timeout problem Pin
nour1233-Jan-09 6:59
nour1233-Jan-09 6:59 
GeneralRe: Session timeout problem Pin
Colin Angus Mackay3-Jan-09 7:07
Colin Angus Mackay3-Jan-09 7:07 
GeneralRe: Session timeout problem Pin
nour1233-Jan-09 18:41
nour1233-Jan-09 18:41 
GeneralRe: Session timeout problem Pin
Aman Bhullar3-Jan-09 23:12
Aman Bhullar3-Jan-09 23:12 
AnswerRe: Session timeout problem Pin
N a v a n e e t h3-Jan-09 5:19
N a v a n e e t h3-Jan-09 5:19 
GeneralRe: Session timeout problem Pin
nour1233-Jan-09 5:59
nour1233-Jan-09 5:59 
GeneralRe: Session timeout problem Pin
Colin Angus Mackay3-Jan-09 7:01
Colin Angus Mackay3-Jan-09 7:01 
QuestionHow to Display Resize Box to the Seleted Image in Asp.net using Javascript Pin
dilipmca043-Jan-09 2:52
dilipmca043-Jan-09 2:52 
QuestionGridview Pin
ksarchana3-Jan-09 1:09
ksarchana3-Jan-09 1:09 
AnswerRe: Gridview Pin
Abhijit Jana3-Jan-09 1:12
professionalAbhijit Jana3-Jan-09 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.