954,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Object Null Reference ??

Hi There

I get the following error when clicking on btn
This code works perfectly on some machines but does not work on others

protected void btnSave_Click(object sender, EventArgs e)
            {
                if (btnSave.Text.ToUpper() == "CREATE")
                    this.InsertInvoice();
                else if (btnSave.Text.ToUpper() == "SAVE CHANGES")
                    this.UpdateInvoice();
            }


private void InsertInvoice()
        {
            String  sqlCommand  = String.Empty;
            DataSet result      = null;

            //Create the command.
            sqlCommand = String.Format("EXEC nga_InsertPaymentInvoice {0}, '{1}', {2}, '{3}', '{4}', '{5}'", 
                                       1, ddVendors.Text, "0.14", txtReasonForPayment.Text, 
                                       txtAuthoriser.Text, DateTime.Now.ToLongDateString());

            //Execute the command and get the new invoice id.
            result = m_dbHandler.SmartGetDataSet(sqlCommand);
            
            //Redirect.
            base.Response.Redirect(String.Format("FulfillmentPayment.aspx?Command=Edit&InvoiceId={0}",
                                   result.Tables[0].Rows[0][0]));
        }


Here is the stored procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[nga_InsertPaymentInvoice] @invoiceType INT, @couplingEntity NVARCHAR(256), @taxRate FLOAT,
										  @reasonForPayment TEXT, @authoriser NVARCHAR(256), @dateCreated DATETIME

AS

	BEGIN

	INSERT INTO nga_PaymentInvoices VALUES (@invoiceType, @couplingEntity, @dateCreated, @taxRate, @reasonForPayment, 
										    @authoriser);

	SELECT InvoiceId FROM nga_PaymentInvoices 

	WHERE invoiceType=@invoiceType AND couplingEntity=@couplingEntity AND dateCreated=@dateCreated AND
		  AtTimeTaxRate=@taxRate AND Authoriser=@authoriser;

	END


Does anyone know why i get this error ??? I am using SQL server 2005 developer edition,visual studio 2008 C#

Thanks in advance

cVz
Junior Poster
140 posts since Mar 2008
Reputation Points: 29
Solved Threads: 7
 

Oh yes and this is where i get the error ...

#
//Redirect.
#
base.Response.Redirect(String.Format("FulfillmentPayment.aspx?Command=Edit&InvoiceId={0}",
#
result.Tables[0].Rows[0][0]));

With error

Object reference not set to an instance of an object.
cVz
Junior Poster
140 posts since Mar 2008
Reputation Points: 29
Solved Threads: 7
 
result = m_dbHandler.SmartGetDataSet(sqlCommand);


That line must be handling an exception and returning a null. You need to check if (result == null) then the operation was not sucessful.

if (result == null)
Response.Redirect("~/error.aspx");
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You