locked
How to collect ArrayList Item from C# ??? RRS feed

  • Question

  • User-982972619 posted

     Hi guys, I have a problem maybe you guys could help.

    I have this code in C#:

     

    1    			BOSTx Tex = GetTx(CLSReportConstants.TrnMasterID.FQN2,"myQuery");
    2    			try
    3    			{
    4    
    5    				string querySalesPerson = "SELECT     dbo.BOS_GL_Workplace.WpszState, BOS_PI_Employee_1.szName, dbo.BOS_PI_Employee.szName AS Expr1, dbo.BOS_PI_Employee.szEmployeeId, "+
    6    					" dbo.BOS_PI_Division.szName AS Divisi, dbo.BOS_PI_Team.szDescription "+
    7    					" FROM         dbo.BOS_PI_Employee INNER JOIN "+
    8    					" dbo.BOS_GL_Workplace ON dbo.BOS_PI_Employee.szWorkplaceId = dbo.BOS_GL_Workplace.szWorkplaceId LEFT OUTER JOIN "+
    9    					" dbo.BOS_PI_Division ON dbo.BOS_PI_Employee.szDivisionId = dbo.BOS_PI_Division.szDivisionId LEFT OUTER JOIN "+
    10   					" dbo.BOS_PI_Team ON dbo.BOS_PI_Employee.szTeamId = dbo.BOS_PI_Team.szTeamId LEFT OUTER JOIN "+
    11   					" dbo.BOS_PI_Employee BOS_PI_Employee_1 ON dbo.BOS_PI_Employee.szSupervisorId = BOS_PI_Employee_1.szEmployeeId "; //+ 
    12   				//"WHERE     (dbo.BOS_PI_Employee.szEmployeeId = '"+szsalesPrsn+"')";
    13   				//					" WHERE BOS_GL_Workplace.WpszState = '" + szProvince + "' AND  BOS_PI_Employee.szName = '" + szsalesPrsn + "' AND BOS_PI_Employee_1.szName = '" + szSupervisor + "'";
    14   
    15   				//BOSTx Tex = GetTx(CLSReportConstants.TrnMasterID.FQN2,"myQuery");
    16   				OleDbCommand comm = Tex.GetTextCommand();
    17   				comm.CommandText = querySalesPerson;
    18   
    19   				DataTable table = new DataTable();
    20   				OleDbDataAdapter dadap = new OleDbDataAdapter(comm);
    21   				dadap.Fill(table);
    22   
    23   				ArrayList salesmen = new ArrayList();
    24   				foreach(DataRow row in table.Rows)
    25   				{
    26   					//cs_sales s = new  cs_sales();
    27   					if (row["WpszState"] == System.DBNull.Value)
    28   					{
    29   						sz_province = "   ";
    30   					}
    31   					else
    32   					{
    33   						sz_province = row["WpszState"].ToString();
    34   					}
    35   					if (row["szName"] == System.DBNull.Value)
    36   					{
    37   						sz_supervisorname = "\t\t";
    38   					}
    39   					else
    40   					{
    41   						sz_supervisorname = row["szName"].ToString();
    42   					}
    43   					if (row["Expr1"] == System.DBNull.Value)
    44   					{
    45   						sz_salemanname = "\t\t";
    46   					}
    47   					else
    48   					{
    49   						sz_salemanname = row["Expr1"].ToString();
    50   					}
    51   					if (row["szEmployeeId"] == System.DBNull.Value)
    52   					{
    53   						sz_salesmancode = "\t   ";
    54   					}
    55   					else
    56   					{
    57   						sz_salesmancode = row["szEmployeeId"].ToString();
    58   					}
    59   					if (row["Divisi"].ToString().Equals(System.DBNull.Value))
    60   					{
    61   						sz_Divisi = "\t\t		";
    62   					}
    63   					else
    64   					{
    65   						sz_Divisi = row["Divisi"].ToString();
    66   					}
    67   					if (row["szDescription"].ToString().Equals(System.DBNull.Value))
    68   					{
    69   						sz_typeOp = "\t\t		";
    70   					}
    71   					else
    72   					{
    73   						sz_typeOp = row["szDescription"].ToString();
    74   					}
    75   			
    76   					salesmen.Add(sz_province);//+"\t\t    "+sz_supervisorname+"\t\t"+sz_salemanname+"\t\t\t"+sz_salesmancode);//+"\t\t		"+sz_Divisi+"\t\t		"+sz_typeOp+"\n");
    77   					salesmen.Add(sz_supervisorname);
    78   					salesmen.Add(sz_salemanname);
    79   					salesmen.Add(sz_salesmancode);
    80   					salesmen.Add(sz_Divisi);
    81   					salesmen.Add(sz_typeOp);
    82   				}
    83   
    84   				Tex.CloseConnection();
    85   				return salesmen;
    86   
    87   			}
    88   			catch(Exception e)
    89   			{
    90   				Tex.CloseConnection();
    91   				throw e;
    92   			}
    
      

     The code above is for collecting data from database and store it in ArrayList Item called salesmen. The C# work just fine it collects all data column from DB just the way it should. Then I have this code in VB.NET:

     

    1    For i As Integer = 0 To slsList.Count - 1
    2        m_lp.Print(m_lp.PadL(slsList(i), 30), True)
    3    Next
     The Code above is for calling the Arraylist Class and take the Arraylist Item from C#(through reference) and store it in ArrayList Variable
     called slsList. The code work just fine but the problem is the slsList(i) method takes ALL the item from the C# class and stack it together.
    What I want to do is how can I take the Item from C# class One by One, so maybe it would be like:
    m_lp.Print(m_lp.PadL(slsList(i,0), 30), True)
    m_lp.Print(m_lp.PadL(slsList(i,1), 30), True)
    Please guys I really need your help. Any kinds of help I would appreciate it, Thanks.
     
    Best Regards.
    FYI: I use Visual Studio.NET 2003 and SQL server 2000. 
     
     
    Monday, April 21, 2008 4:34 AM

All replies

  • User-982972619 posted

    Hi guys, any suggestions ?. Maybe I wasn't clear 'bout what I'm asking.

    From the code above I have these string variable datatype which are:

    public string sz_province;

    public string sz_supervisorname;

    public string sz_salemanname;

    public string sz_salesmancode

    public string sz_Divisi;
    public string sz_typeOp;
    Those variable then added to an Arraylist called salesmen, which is you can see on line 76-81. Those variable
    contained data column from database.
    What I want is how can I accessed those elements(sz_Provinece,sz_supervisorname,etc) and use it on the VB.NET code
    so I can manage it one-by-one. So Instead of this:
    1    For i As Integer = 0 To slsList.Count - 1
    2 m_lp.Print(m_lp.PadL(slsList(i), 30), True)
    3 Next
    Myabe I could do like this:
    m_lp.Print(m_lp.PadL(sz_province, 30), True)
    m_lp.Print(m_lp.PadL(sz_supervisorname, 30), True)
    .
    .
    .
    I know the assumption above far from correct, so maybe you guys out there could give me some help, please guys.
    If I could get this one done, probably I could extend my career much longer. Thanks.
     
    Best Regards. 
     
    Tuesday, April 22, 2008 11:44 PM