Advertisement

07.02.2008 at 01:33PM PDT, ID: 23535033
[x]
Attachment Details

easy question to create multiple csv files. urgent.

Asked by mathieu_cupryk in C# Programming Language, Microsoft Visual Basic.Net, Microsoft Visual C#.Net

I have the following function:
In the variable
dr.ItemArray[0] we must check if it changes
it can start of with a "01"
then switch to "02"
or start with "01"
then switch to "04"

Now when it changes I need to create a new csv knowing that the values has changed.

The filename will have an extension for example filename01 for "01"
filename02 for "02"
and so on.

we can have
"01"
"02"
"04"
"64"
the dataset is inorder.
Please see the code below and see what we can modify.
I have attached the code snippet.


            foreach (DataRow dr in dt.Rows)
            {
                if dr.ItemArray[0] ==  "02"
save the file and continue going throught all the rows
and so forth.
                sw.Write("Item");   //ProductContext
                sw.Write(",");
                sw.Write("Item Number");  // ProductAttribute
                sw.Write(",");
                sw.Write(dr.ItemArray[3].ToString());
                sw.Write(",");
                sw.Write(dr.ItemArray[1].ToString().TrimEnd());
                sw.Write(",");
                sw.Write("MT"); // UOM
                sw.Write(",");
                sw.Write("");// PrimaryUOM
                sw.Write(",");
                sw.Write("Price List Line");// LineType
                sw.Write(",");
                sw.Write(""); // PriceBreakType
                sw.Write(",");
                sw.Write("Unit Price"); // ApplicationMethod
                sw.Write(",");
                sw.Write(""); // BreakUOM
                sw.Write(",");
                sw.Write(""); // BreakUOMAttibute
                sw.Write(",");
                sw.Write((Convert.ToDecimal(dr.ItemArray[2]).ToString("#,##0.000"))); // Straight Price
                sw.Write(",");
                sw.Write(""); // DynamicFormula
                sw.Write(",");
                sw.Write(""); // StaticFormula
                sw.Write(",");
                sw.Write(_effectDTM); // SCTEffdtm
                sw.Write(",");
                sw.Write(""); // EndDate
                sw.Write(",");
                sw.Write("220"); // Precedence
                sw.Write(",");
                sw.Write("CWB"); // Context
                sw.Write(",");
                sw.Write("0"); // Attribute1
                sw.Write(sw.NewLine);
            }
            sw.Close();


        }
    }Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
public static void ProduceADVPriceListLoad(string _fileName, string _priceListHeaderID, string _effectDTM, string _sctPriceListName)
        {
            System.Data.DataSet DSNew = new DataSet();
           
            // Create the CSV file to which data will be exported.
            StreamWriter sw = new StreamWriter(_fileName, false);
            // First we will write the headers.
            // Get Ottawa Grades
            InitialPriceReporting.InitialPriceReportingServiceWS.InitialPriceReportingService WS = new InitialPriceReporting.InitialPriceReportingServiceWS.InitialPriceReportingService();
            string Status = null;
 
            sw.Write("Price List Name");
            sw.Write(",");
            sw.WriteLine(_sctPriceListName);
            
            sw.Write ("Price List");
            sw.Write (",");
            sw.WriteLine("Y");
            sw.WriteLine("");
            sw.WriteLine("");
            sw.WriteLine(Header);
          
            DSNew = WS.GetQPOPMGrades(_priceListHeaderID, ref Status);
            
            DataTable dt = DSNew.Tables[0];
 
            int iColCount = dt.Columns.Count;
 
       
            // Now write all the rows.
            foreach (DataRow dr in dt.Rows)
            {
 
                sw.Write("Item");   //ProductContext
                sw.Write(",");
                sw.Write("Item Number");  // ProductAttribute
                sw.Write(",");
                sw.Write(dr.ItemArray[3].ToString());
                sw.Write(",");
                sw.Write(dr.ItemArray[1].ToString().TrimEnd());
                sw.Write(","); 
                sw.Write("MT"); // UOM
                sw.Write(","); 
                sw.Write("");// PrimaryUOM
                sw.Write(","); 
                sw.Write("Price List Line");// LineType
                sw.Write(","); 
                sw.Write(""); // PriceBreakType
                sw.Write(","); 
                sw.Write("Unit Price"); // ApplicationMethod
                sw.Write(","); 
                sw.Write(""); // BreakUOM
                sw.Write(","); 
                sw.Write(""); // BreakUOMAttibute
                sw.Write(",");
                sw.Write((Convert.ToDecimal(dr.ItemArray[2]).ToString("#,##0.000"))); // Straight Price
                sw.Write(","); 
                sw.Write(""); // DynamicFormula
                sw.Write(","); 
                sw.Write(""); // StaticFormula
                sw.Write(","); 
                sw.Write(_effectDTM); // SCTEffdtm
                sw.Write(","); 
                sw.Write(""); // EndDate
                sw.Write(","); 
                sw.Write("220"); // Precedence
                sw.Write(","); 
                sw.Write("CWB"); // Context
                sw.Write(","); 
                sw.Write("0"); // Attribute1
                sw.Write(sw.NewLine);
            }
            sw.Close();
 
 
        }
    }
[+][-]07.02.2008 at 02:37PM PDT, ID: 21920953

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.03.2008 at 07:38PM PDT, ID: 21930713

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.03.2008 at 07:51PM PDT, ID: 21930754

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, Microsoft Visual Basic.Net, Microsoft Visual C#.Net
Sign Up Now!
Solution Provided By: FernandoSoto
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.03.2008 at 08:04PM PDT, ID: 21930790

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628