943,928 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1814
  • ASP.NET RSS
Mar 3rd, 2009
0

Object Null Reference ??

Expand Post »
Hi There

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


C# Syntax (Toggle Plain Text)
  1. protected void btnSave_Click(object sender, EventArgs e)
  2. {
  3. if (btnSave.Text.ToUpper() == "CREATE")
  4. this.InsertInvoice();
  5. else if (btnSave.Text.ToUpper() == "SAVE CHANGES")
  6. this.UpdateInvoice();
  7. }
  8.  
  9.  
  10. private void InsertInvoice()
  11. {
  12. String sqlCommand = String.Empty;
  13. DataSet result = null;
  14.  
  15. //Create the command.
  16. sqlCommand = String.Format("EXEC nga_InsertPaymentInvoice {0}, '{1}', {2}, '{3}', '{4}', '{5}'",
  17. 1, ddVendors.Text, "0.14", txtReasonForPayment.Text,
  18. txtAuthoriser.Text, DateTime.Now.ToLongDateString());
  19.  
  20. //Execute the command and get the new invoice id.
  21. result = m_dbHandler.SmartGetDataSet(sqlCommand);
  22.  
  23. //Redirect.
  24. base.Response.Redirect(String.Format("FulfillmentPayment.aspx?Command=Edit&InvoiceId={0}",
  25. result.Tables[0].Rows[0][0]));
  26. }

Here is the stored procedure

ASP.NET Syntax (Toggle Plain Text)
  1. set ANSI_NULLS ON
  2. set QUOTED_IDENTIFIER ON
  3. go
  4.  
  5.  
  6. ALTER PROCEDURE [dbo].[nga_InsertPaymentInvoice] @invoiceType INT, @couplingEntity NVARCHAR(256), @taxRate FLOAT,
  7. @reasonForPayment TEXT, @authoriser NVARCHAR(256), @dateCreated DATETIME
  8.  
  9. AS
  10.  
  11. BEGIN
  12.  
  13. INSERT INTO nga_PaymentInvoices VALUES (@invoiceType, @couplingEntity, @dateCreated, @taxRate, @reasonForPayment,
  14. @authoriser);
  15.  
  16. SELECT InvoiceId FROM nga_PaymentInvoices
  17.  
  18. WHERE invoiceType=@invoiceType AND couplingEntity=@couplingEntity AND dateCreated=@dateCreated AND
  19. AtTimeTaxRate=@taxRate AND Authoriser=@authoriser;
  20.  
  21. END

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

Thanks in advance
Last edited by cVz; Mar 3rd, 2009 at 3:52 am.
Similar Threads
cVz
Reputation Points: 29
Solved Threads: 7
Junior Poster
cVz is offline Offline
139 posts
since Mar 2008
Mar 3rd, 2009
0

Re: Object Null Reference ??

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

Quote ...
Object reference not set to an instance of an object.
cVz
Reputation Points: 29
Solved Threads: 7
Junior Poster
cVz is offline Offline
139 posts
since Mar 2008
Mar 6th, 2009
0

Re: Object Null Reference ??

c# Syntax (Toggle Plain Text)
  1. 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.

c# Syntax (Toggle Plain Text)
  1. if (result == null)
  2. Response.Redirect("~/error.aspx");
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Plz.. how to send nearly 700 e-mail at a time in asp.net
Next Thread in ASP.NET Forum Timeline: why use @reference directive





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC