Object Null Reference ??

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Object Null Reference ??

 
0
  #1
Mar 3rd, 2009
Hi There

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


  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

  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.
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: Object Null Reference ??

 
0
  #2
Mar 3rd, 2009
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.
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Object Null Reference ??

 
0
  #3
Mar 6th, 2009
  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.

  1. if (result == null)
  2. Response.Redirect("~/error.aspx");
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC