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

Recommended Answers

All 2 Replies

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.

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");
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.