Avatar of mathieu_cupryk
Flag for Canada

asked on 

Use of unassigned local variable 'sw'.

System.Data.DataSet DSQPOPMGrades = new DataSet();
            System.Data.DataSet DSPiceListHeader = new DataSet();
            string FileName = clsGlobal.Global.Path + "\\" + "AdvancePricingLoad";
            string Status = null;  
            // Create the CSV file to which data will be exported.
            StreamWriter sw;
            //StreamWriter sw = new StreamWriter(FileName, false);
            // First we will write the headers.
            InitialPriceReporting.InitialPriceReportingServiceWS.InitialPriceReportingService WS = new InitialPriceReporting.InitialPriceReportingServiceWS.InitialPriceReportingService();
            WS.Credentials = System.Net.CredentialCache.DefaultCredentials;
            DSQPOPMGrades = WS.GetQPOPMGrades(_priceListHeaderID, ref Status);
            DSPiceListHeader = WS.GetPriceListHeader (ref Status);

            DataTable dtPLH = DSPiceListHeader.Tables[0];
            DataTable dt = DSQPOPMGrades.Tables[0];

            int iColCount = dt.Columns.Count;

            // User to keep track of the last dr.ItemArray[0] to see if wee need to close
            // the file or not
            String filepart = "";
            foreach (DataRow dr in dt.Rows)
                // Check to see if this is the first time through or dr.ItemArray[0]
                // has changed and the file needs to be closed and a new file opened

                if (filepart == null || filepart != dr.ItemArray[0].ToString())
                    // The first time through the writter will be closed
                    if (sw != null) sw.Close();  =======================> error CS0165.
                    // Save the value that will determine if we need to start a new file
                    filepart = dr.ItemArray[0].ToString();
                    // Open a new file with the value dr.ItemArray[0] on the end of the name
                    sw = new StreamWriter(FileName + filepart + _statusType + ".csv", false);

                    // Look a discount count

                    ///// Header only once per file
                    sw.Write("Price List Name");

                    sw.Write("Price List");
.NET ProgrammingC#

Avatar of undefined
Last Comment

8/22/2022 - Mon