troubleshooting Question

ExecuteScalar() issue in C#.net

Avatar of tattsnyc
tattsnyc asked on
C#
9 Comments1 Solution2246 ViewsLast Modified:
This problem wil ldrive me to drink .I am working on a web page  in c#.net . I want to use  executescalar() to  execute a stored procedure which wil lreturn one value of 1. I then want to say if the executescalar =1 then do this else do that .It doesnt seem to woirk the same as Vb.net so I am lost and have spent many hours trying to figure this out.  I get the following error currently:

c:\inetpub\wwwroot\WebInvoice\Invoice.aspx.cs(126): Cannot implicitly convert type 'object' to 'bool'


No matter what ,Howevber, I get some kind of error while debugging.  Please advise ASAP. Thanks in advanmce for your help and time.  Bellow is the code for the Stored Procedure and also some Page code.

Stored Procedure:
CREATE PROCEDURE [AAAInvoiceAspxReportCK]
@Inv Nvarchar(20),
@Cust Nvarchar(20)
as


Drop Table OnlineInvoiceCK




Select Distinct count(invoice) as Count
Into OnlineInvoiceCK
FROM ARSalesHeader

where (@cust=ARSalesHeader.CustomerID) And (Invoice = @Inv)
GO

Page Code:

finally
                  {
                              
                        SqlConnection ConnCK = new SqlConnection
                                                                   ("Server=Apps1;Database=ChainDynamics;User ID=sa;Trusted_Connection=False" );
                        SqlCommand CmdCK = new SqlCommand("AAAInvoiceAspxReportCK",ConnCK);
                        CmdCK.CommandType = CommandType.StoredProcedure;
                        SqlParameter invCK = new SqlParameter("@Inv", SqlDbType.NVarChar,20);
                        CmdCK.Parameters.Add(invCK);
                        invCK.Direction = ParameterDirection.Input;
                        invCK.Value = Request.QueryString["inv"];
                        SqlParameter custCK = new SqlParameter("@Cust", SqlDbType.NVarChar,20);
                        CmdCK.Parameters.Add(custCK);
                        custCK.Direction = ParameterDirection.Input;
                        custCK.Value = Session["LogonID"];
                        
                        try
                        {
                              ConnCK.Open();
                              object correct = new object();
                              object a = new object();
                              a=1;
                    correct = CmdCK.ExecuteScalar();
                              if(correct =a)
                                
                              {

                                //Page code }
                        finally
                        {
                              
                              crReportDocument.Close();
                              ConnCK.Close();
                        }
                        
                  
            
                  }
      


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros