Casting in forEach ?

Hi guys,
I have a UsersCatalog bean being set in a servlet, and this catalog contains lots of User objects.
Servlet:
Collection userslist = new ArrayList();
User user1 = new User("John");
User user2 = new User("Peter");
userslist.add(user1);
userslist.add(user2);
UsersCatalog catalog = new UsersCatalog();
catalog.usersitems = userslist;
request.setAttribute("mycatalog",catalog)
in the jsp I've got a bean called "catalog" like this:
<jsp:usebean id="catalog" class="beans.UsersCatalog" scope="request">
now I want to iterate those "users" (up there):
(here the problem)
<c:forEach var="user" items="${catalog.usersitems}">
${user.firstname}
</c:forEach>
I don't know how I can iterate those users. Given that the usersitems is a collection (which is ok for iteration purposes), how can I have acess to the User object and thus access its variables?
I've tried various different ways of iterate them but can't see the result on the screen, but surprinsingly, when I use scriptlets and a java Iterator they show up (!?)
Should I create one bean for each of those catalog users? if I have 100 users, would I have 100 beans ?
I'm stuck on this for 2 days and since i have no internet at home (just moved in), I'm going crazy....
I would really appreciate if someone could give me a hand with this...
Thanks in advance guys
catalog.add(
Message was edited by:
bbrendler

Hi bckrispi, thanks for the reply.
I'm gonna try this when I get home today and since I have no internet there I let you know tomorrow about the result of that.
Thanks a lot.
Bruno
Message was edited by:
bbrendler

Similar Messages

  • c:forEach tag

    Hi,
    I'm trying to use the forEach tag in the jstl in order to display the contents of an Hashtable. The table is written in the session and arrives populated with the results of a SELECT query.
    The elements of the table are instances of a class of mine, and I'd like to display some of the fields (all accessible by getters and setters) of this class.
    The fact is that if I try to write the elements of the table, I obviously get the class of the elements followed by their ID number (like Object@64383265), but if I try to access a field, I get nothing.
    Here is the code reading the elements:
    risposta = Hashtable in the session, contains dap.obj.Notizia objects
    <jsp:useBean id="notizia" scope="page" class="dap.obj.Notizia" />
    <c:forEach var="notizia" items="${risposta}">
         <c:out value="${notizia}" />
    </c:forEach>
    And if I try to replace the line of output with:
         <c:out value="${notizia.ID}" />
    I obtain an error saying:
    (...) Unable to find a value for "ID" in object of class "java.util.Hashtable$Entry" using operator "." (null)
    If I use
         <c:out value="${notizia.[ID]}" />
    no errors and nothing appears..
    Do I need to know something about the cast inside the tags of jstl or am I trying to do something wrong?
    I admit that these are my first days with jstl, but I've searched among some books with no results. Thanks in advantage for your jelp

    Seeing as you are accessing a Map, the object you get back is a Map.Entry
    So you can access it as ${notizia.key} to get the hash key, and ${notizia.value} to get the object of type Notizia
    <c:forEach var="notizia" items="${risposta}">
    <c:out value="${notizia.value.ID}" />
    </c:forEach>Cheers,
    evnafets

  • Create RSS feed for Narrow casting

    We are using narrow casting and we can stream content to it using an RSS-feed.
    We want to do the following: - Create an rss feed of an exchange (mailbox or calendar) using a script. I think it is just like this link. Or as shown below: 
    ###Code from http://poshcode.org/?show=669
    # Creates an RSS feed
    # Parameter input is for "site": Path, Title, Url, Description
    # Pipeline input is for feed items: hashtable with Title, Link, Author, Description, and pubDate keys
    Function New-RssFeed
    param (
    $Path = "$( throw 'Path is a mandatory parameter.' )",
    $Title = "Site Title",
    $Url = "http://$( $env:computername )",
    $Description = "Description of site"
    Begin {
    # feed metadata
    $encoding = [System.Text.Encoding]::UTF8
    $writer = New-Object System.Xml.XmlTextWriter( $Path, $encoding )
    $writer.WriteStartDocument()
    $writer.WriteStartElement( "rss" )
    $writer.WriteAttributeString( "version", "2.0" )
    $writer.WriteStartElement( "channel" )
    $writer.WriteElementString( "title", $Title )
    $writer.WriteElementString( "link", $Url )
    $writer.WriteElementString( "description", $Description )
    Process {
    # Construct feed items
    $writer.WriteStartElement( "item" )
    $writer.WriteElementString( "title", $_.title )
    $writer.WriteElementString( "link", $_.link )
    $writer.WriteElementString( "author", $_.author )
    $writer.WriteStartElement( "description" )
    $writer.WriteRaw( "<![CDATA[" ) # desc can contain HTML, so its escaped using SGML escape code
    $writer.WriteRaw( $_.description )
    $writer.WriteRaw( "]]>" )
    $writer.WriteEndElement()
    $writer.WriteElementString( "pubDate", $_.pubDate.toString( 'r' ) )
    $writer.WriteElementString( "guid", $homePageUrl + "/" + [guid]::NewGuid() )
    $writer.WriteEndElement()
    End {
    $writer.WriteEndElement()
    $writer.WriteEndElement()
    $writer.WriteEndDocument()
    $writer.Close()
    ### end code from http://poshcode.org/?show=669
    ## Get the Mailbox to Access from the 1st commandline argument
    $MailboxName = $args[0]
    ## Load Managed API dll
    Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"
    ## Set Exchange Version
    $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1
    ## Create Exchange Service Object
    $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
    ## Set Credentials to use two options are availible Option1 to use explict credentials or Option 2 use the Default (logged On) credentials
    #Credentials Option 1 using UPN for the windows Account
    $psCred = Get-Credential
    $creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
    $service.Credentials = $creds
    #Credentials Option 2
    #service.UseDefaultCredentials = $true
    ## Choose to ignore any SSL Warning issues caused by Self Signed Certificates
    ## Code From http://poshcode.org/624
    ## Create a compilation environment
    $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
    $Compiler=$Provider.CreateCompiler()
    $Params=New-Object System.CodeDom.Compiler.CompilerParameters
    $Params.GenerateExecutable=$False
    $Params.GenerateInMemory=$True
    $Params.IncludeDebugInformation=$False
    $Params.ReferencedAssemblies.Add("System.DLL") | Out-Null
    $TASource=@'
    namespace Local.ToolkitExtensions.Net.CertificatePolicy{
    public class TrustAll : System.Net.ICertificatePolicy {
    public TrustAll() {
    public bool CheckValidationResult(System.Net.ServicePoint sp,
    System.Security.Cryptography.X509Certificates.X509Certificate cert,
    System.Net.WebRequest req, int problem) {
    return true;
    $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
    $TAAssembly=$TAResults.CompiledAssembly
    ## We now create an instance of the TrustAll and attach it to the ServicePointManager
    $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
    [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
    ## end code from http://poshcode.org/624
    ## Set the URL of the CAS (Client Access Server) to use two options are availbe to use Autodiscover to find the CAS URL or Hardcode the CAS to use
    #CAS URL Option 1 Autodiscover
    $service.AutodiscoverUrl($MailboxName,{$true})
    "Using CAS Server : " + $Service.url
    #CAS URL Option 2 Hardcoded
    #$uri=[system.URI] "https://casservername/ews/exchange.asmx"
    #$service.Url = $uri
    ## Optional section for Exchange Impersonation
    #$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)
    # Bind to the Contacts Folder
    $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
    $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
    $psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
    #Define ItemView to retrive just 50 Items
    $ivItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(50)
    $fiItems = $service.FindItems($Inbox.Id,$ivItemView)
    [Void]$service.LoadPropertiesForItems($fiItems,$psPropset)
    $feedItems = @()
    foreach($Item in $fiItems.Items){
    "processing Item " + $Item.Subject
    $PostItem = @{}
    $PostItem.Add("Title",$Item.Subject)
    $PostItem.Add("Author",$Item.Sender.Address)
    $PostItem.Add("pubDate",$Item.DateTimeReceived)
    $PostItem.Add("link",("https://" + $service.Url.Host + "/owa/" + $Item.WebClientReadFormQueryString))
    $PostItem.Add("description",$Item.Body.Text)
    $feedItems += $PostItem
    $feedItems | New-RssFeed -path "c:\temp\Inboxfeed.xml" -title ($MailboxName + " Inbox")
    But it is a Exchange Management Shell script an we would like to execute it like a .php file.
    Can anyone help me with this please?
    I would like to thank you in advance.
    Kind regards,
    Jordi Martin Lago

    That's not a Exchange Management Shell script its just a normal powershell script that uses the EWS Managed API
    http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx . So you can run it from any workstation or server where you have powershell and the Managed API library installed.
    You will need to update the line
    Add-Type -Path
    "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"    
    To
    Add-Type -Path
    "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"    
        To cater for the latest version of the Managed API.
      You can scheduled powershell scripts to run using the Task Scheduler eg
    http://community.spiceworks.com/how_to/show/17736-run-powershell-scripts-from-task-scheduler
    Cheers
    Glen

  • Cannot cast from SOMETHING to SOMETHING (Error in 1.4) (Works in 1.6)

    Our company have developed an accounting program, and it is already near completion.
    We developed it with JavaBean and Eclipse in Windows Environment with JRE 1.6.0_05
    When we tried to compile and run the program in our linux environment (Server) that runs on 1.4 , the casting error occured..
    we have written a program to generate all casting errors that occurred in our project.
    import java.math.*;
    import java.util.*;
    public class testnow {
         public static void main(String[] args){
              //Declare ALL Primitive!
              int TestINT = 150;
              Boolean TestBOOL = true;
              String TestSTR = "Streng" + "th";
              BigDecimal TestDCM = BigDecimal.valueOf(20);
              Date TestDATE = new Date();
              //Declare ALL Object
              Object TestINTObj = 150;
              Object TestSTRObj = "Strength";
              Object TestDCMObj = BigDecimal.valueOf(20);
              Object TestBOOLObj = true;
              Object TestDATEObj = new Date();
              if(TestINT == (Integer)TestINTObj){
                   System.out.println("TEST Integer PASSED");
              if(TestSTR.equals((String)TestSTRObj)){
                   System.out.println("TEST String PASSED");
              if(TestDCM.equals(TestDCMObj)){
                   System.out.println("TEST Decimal PASSED");
              if(TestBOOL == (Boolean)TestBOOLObj){
                   System.out.println("TEST Boolean PASSED");
              if(TestDATE.equals((Date)TestDATEObj)){
                   System.out.println("TEST Date PASSED");
    }the following is what happened when i run javac testnow.java
    1. ERROR in testnow.java
    (at line 6)
    Integer TestINT = 150;
    ^^^^^^^
    Type mismatch: cannot convert from int to Integer
    2. ERROR in testnow.java
    (at line 7)
    Boolean TestBOOL = (Boolean)true;
    ^^^^^^^^^^^^^
    Cannot cast from boolean to Boolean
    3. ERROR in testnow.java
    (at line 11)
    Object TestINTObj = (Object)150;
    ^^^^^^^^^^^
    Cannot cast from int to Object
    4. ERROR in testnow.java
    (at line 14)
    Object TestBOOLObj = true;
    ^^^^^^^^^^^
    Type mismatch: cannot convert from boolean to Object
    4 problems (4 errors)
    in our windows development JRE 1.6 , it run well and gives the following output :
    TEST Integer PASSED
    TEST String PASSED
    TEST Decimal PASSED
    TEST Boolean PASSED
    TEST Date PASSED
    how do we solve this? i mean we have been using this "convenience" casting all over our code . :(
    please help
    thanks a lot.
    Cheers and God Bless,
    Chowi

    You've got a lot of problems there, and not all of them are due to Java version incompatibilites. I'll take them in the order I see them. public static Object FindDataInTable(ArrayList TargetTable, String TypeColumn,
             String TargetColumn, Object TargetData, String ReturnedColumn)&#x7B; The convention is to give methods and variables names that start with lowercase letters. That makes your code easier to read, which makes it easier for us to help you. Later on, I see you also use a mix of underscores and camelcase. Underscores should be used only in constant names; class, method and variable names should use only camelcase.
    Also, if you don't have a good reason to make that first argument an ArrayList, you should declare it as a List instead. That leaves the calling code the option of using a different List implementation should they need to.
    Next, you assign a primitive value to an Object reference: Object ReturnedObject = 0; That requires autoboxing, as others have pointed out, which didn't exist in JDK 1.4. Even if you could use autoboxing though, that assignment would be a bad idea; a variable of type Object should be assigned a default value of {color:000080}null{color}, not a number. However, you may not need to declare that variable at all, as I explain later.
    Next you use a "foreach" loop, another feature that was added in JDK 1.5; you'll have to switch to the old-style loop if you want this code to work under JDK 1.4. While you're at it, you should declare your "SingleRow" variable inside the loop, since it's not used anywhere else: for (Iterator it = TargetTable.iterator(); it.hasNext(); ) {
        Model_DatabaseQuery SingleRow = (Model_DatabaseQuery)it.next(); Next I see you using matches() to compare String values: if(TypeColumn.matches("String")){
        if(((String)TargetData).matches((String)CheckData))&#x7B; You get away with that because the strings contain only letters, but you need to look up the docs for matches() so you'll understand why you shoudn't be using it here. But this is nothing compared to the next issue: if((Integer)TargetData == (Integer)CheckData)&#x7B; // WRONG WRONG WRONG That can't possibly have worked right, no matter what version of Java you ran it under. You NEVER use == to compare the values objects! You should have been using equals() for all those comparisions, not matches(), and definitely not ==.
    But I don't see why you're doing all those checks on the column type anyway. All you ever do after that is compare the same two values, so just do it: for (Iterator it = targetTable.iterator(); it.hasNext(); ) {
        Model_DatabaseQuery SingleRow = (Model_DatabaseQuery)it.next();
        Object CheckData = SingleRow.Get_object(TargetColumn);
        if (CheckData != null && CheckData.equals(TargetData)) {
            return SingleRow.Get_object(ReturnedColumn);
    } If there are other columns that you're supposed to ignore, you may still need to check the column type, but you could do that in one {color:000080}if{color} statement; you don't have to check them all separately.

  • Specified cast is not valid

    Hello, I have the following code:
    if (dataTable.Columns.Count > 1)
    strXML = ChartFileNameandPath(chartType) + @"?dataXML=<graph caption='Report ; Summary' subcaption='" + ReportName(reportType) + "' xAxisName='Line Number' yAxisName='Pounds made' rotatelabels='1' slantlabels='1' showNames='1' showvalues='0' numberPrefix='$' exportenabled='1' exportAtClient='1' exportHandler='fcExporter1' exportFormats='PNG=Save as PNG' >";
    //Getting the Subtotal of PoundsMade based on the Line Number column
    //C# linq query
    if (reportType == ReportEnums.Clientsdata) {
    var query = from row in dataTable.AsEnumerable()
    group row by row.Field<string>("ClientName") into grp
    orderby grp.Key
    select new {
    Clientname = grp.Key,
    TotalAmountSpent = grp.Sum(r => r.Field<int>("TotalAmountSpent")) //error here, specified cast is not valid
    foreach (var grp in query) {
    strXML = strXML + "<set name='" + grp.Clientname.ToString() + "' value='" + grp.TotalAmountSpent.ToString() + "'/>";
    I get a error "Specified cast is not valid"
    Part of my store procedure where I'm grabbing it from is:
    SELECT ClientName,
    Mem_Name,
    Mem_Address,
    Mem_city,
    Mem_state,
    Sum(mv.AmountSpent) as TotalAmountSpent,
    (Sum(mv.AmountSpent)/ (CAST(s.TotalBusinessSales as decimal)) * 100) as PercentAmountSpent
    My question is: Am I getting an error because of TotalAmountSpent is an alias?
    Thanks,
    N

    ALTER PROCEDURE usp_Clienttransaction (@FromDate Varchar (30), @ToDate Varchar (30), @Active int)
    AS
    SELECT ClientName,
    Mem_Name,
    Mem_Address,
    Mem_city,
    Mem_state,
    Sum(mv.AmountSpent) as TotalAmountSpent,
    (Sum(mv.AmountSpent)/ (CAST(s.TotalBusinessSales as decimal)) * 100) as PercentAmountSpent
    FROM UnitedDiningClub.dbo.UDC_Member
    JOIN UnitedDiningClub.dbo.UDC_MemberVisits mv
    ON UDC_Member.Mem_ID = mv.MemberId
    JOIN UnitedDiningClub.dbo.UDClub_Client c
    ON c.ClientId = mv.RestaurantId
    INNER JOIN
    ( SELECT RestaurantId, sum(AmountSpent) as TotalBusinessSales
    FROM UnitedDiningClub.dbo.UDC_MemberVisits
    GROUP BY RestaurantId) s
    ON s.RestaurantId = c.ClientId
    GROUP by ClientName, Mem_Name, Mem_Address , Mem_city , Mem_state, s.TotalBusinessSales
    ORDER BY ClientName
    Thats the full procedure.
    Its coming from a sub query. Would an alias effect the results in c#?

  • Casting DataTable to Control

    I'd like to write a general method to dispose of SQL objects using a passed Form object. I'm running Visual Studio Express 2013 for Windows Desktop. The cast is the problem; see the lines with '**'. What type of cast should I use? Thanks!
    public static void Dispose_SQLObjects(Form form)
    foreach(Control control in form.Controls)
    if (control.GetType() == typeof(DataTable))
    **DataTable table = (DataAdapter)control;
    if (table != null) table.Dispose();
    if (control.GetType() == typeof(DataAdapter))
    **DataAdapter adapter = (DataAdapter)control;
    if (adapter != null) adapter.Dispose();
    if (control.GetType() == typeof(BindingSource))
    **BindingSource bs = (BindingSource)control;
    if (bs != null) bs.Dispose();

    I don't know what you are trying to do here.You can't make any cast on anything here in what you are trying to do.
    https://msdn.microsoft.com/en-us/library/system.data.common.dataadapter%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
    https://msdn.microsoft.com/en-us/library/system.data.datatable%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
    https://msdn.microsoft.com/en-us/library/system.windows.forms.control(v=vs.110).aspx
    Java and .NET have the same principles when it come to OO.
    https://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/
    A class defines an object
    A class can be instanciated into a object instance.
    **DataTabletable
    = (DataAdapter)control;
    That statement is saying car I am telling you that you are going to be a house. And once you are a house, I am going to make you a rocket. It's never going to happen. .NET is going to start looking at the defining classe for the objects and say car you can't
    be cast to be a house,  and house you can't be cast to be a rocket.
    It's car cast to a car. It's house cast to a house. It's rocket cast to a rocket.
    Lets say Textbox1 is cast to Object. That can happen becuase System.Object is the base object for everything in .NET. So you pass Object around in code. Object is really a Textbox object. So you get to a point in code where Object needs to be a Textbox object
    again.
    Textbox thetextbox = (TextBox)Object.  That's valid and I hope you understand way it is valid.

  • Error in cast a variable

    these are few lines from my long STORED PROCEDURE actually i am new to oracle 11g please
    declare
    v_s nvarchar2(10);
    p_RN nvarchar2(10);
    begin
    v_s := v_s || cast(p_RN as nvarchar2(10)); - ERROR IS COMING IN THIS LINE
    end;
    error
    ORA-06550: line 5, column 39:
    PLS-00103: Encountered the symbol "(" when expecting one of the following:
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    please somebody help me

    Just a little explanation about the error message.
    ORA-06550: line 5, column 39:
    PLS-00103: Encountered the symbol "(" when expecting one of the following:
    Line 5 column 39 is the starting parenthesis of the "(10)". For using cast you can't add a lenght to the datatype.
    If you change that, then you get a different error message:
    declare
    v_s nvarchar2(10);
    p_RN varchar2(10);
    begin
      v_s := v_s || cast(p_RN as nvarchar2); -- ERROR IS COMING IN THIS LINE
    end;
    Fehler beim Start in Zeile 13 in Befehl:
    declare
    v_s nvarchar2(10);
    p_RN varchar2(10);
    begin
      v_s := v_s || cast(p_RN as nvarchar2); -- ERROR IS COMING IN THIS LINE
    end;
    Fehlerbericht:
    ORA-06550: line 5, column 22:
    PLS-00382: expression is of wrong type
    ORA-06550: line 5, column 3:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:ORA-06550: line 5, column 22:
    PLS-00382: expression is of wrong type
    This shows that you can't convert/cast a nvarchzar type into another nvarchar type.
    It would work if you cast a number into a varchar2 type for example
    declare
    v_s nvarchar2(10);
    p_RN number(10);
    begin
      v_s := v_s || cast(p_RN as nvarchar2); -- ERROR IS COMING IN THIS LINE
    end;
    anonymer Block abgeschlossen.

  • How can I load a .xlsx File into a SQL Server Table using a Foreach Loop Container in SSIS?

    I know I've REALLY struggled with this before. I just don't understand why this has to be soooooo difficult.
    I can very easily do a straight Data Pump of a .xlsX File into a SQL Server Table using a normal Excel Connection and a normal Excel Source...simply converting Unicode to DT_STR and then using an OLE DB Destination of the SQL Server Table.
    If I want to make the SSIS Package a little more flexible by allowing multiple .xlsX spreadsheets to be pumped in by using a Foreach Loop Container, the whole SSIS Package seems to go to hell in a hand basket. I simply do the following...
    Put the Data Flow Task within the Foreach Loop Container
    Add the Variable Mapping Variable User::FilePath that I defined as a Variable and a string within the FOreach Loop Container
    I change the Excel Connection and its Expression to be ExcelFilePath ==> @[User::FilePath]
    I then try and change the Excel Source and its Data Access Mode to Table Name or view name variable and provide the Variable Name User::FilePath
    And that's when I run into trouble...
    Exception from HRESULT: 0xC02020E8
    Error at Data Flow Task [Excel Source [56]]:SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occured. Error code: 0x80004005.
    Error at Data Flow Task [Excel Source [56]]: Opening a rowset for "...(the EXACT Path and .xlsx File Name)...". Check that the object exists in the database. (And I know it's there!!!)
    I don't understand by adding a Foreach Loop Container to try and make this as efficient as possible has caused such an error unless I'm overlooking something. I have even tried delaying my validations and that doesn't seem to help.
    I have looked hard in Google and even YouTube to try and find a solution for this but for the life of me I cannot seem to find anything on pumping a .xlsX file into SQL Server using a Foreach Loop Container.
    Can ANYONE please help me out here? I'm at the end of my rope trying to get this to work. I think the last time I was in this quandry, trying to pump a .xlsX File into a SQL Server Table using a Foreach Loop Container in SSIS, I actually wrote a C# Script
    to write the contents of the .xlsX File into a .csv File and then Actually used the .csv File to pump the data into a SQL Server Table.
    Thanks for your review and am hoping and praying for a reply and solution.

    Hi ITBobbyP,
    If I understand correctly, you want to load data from multiple sheets in an .xlsx file into a SQL Server table.
    If in this scenario, please refer to the following tips:
    The Foreach Loop container should be configured as shown below:
    Enumerator: Foreach ADO.NET Schema Rowset Enumerator
    Connection String: The OLE DB Connection String for the excel file.
    Schema: Tables.
    In the Variable Mapping, map the variable to Sheet_Name, and change the Index from 0 to 2.
    The connection string for Excel Connection Manager is the original one, we needn’t make any change.
    Change Table Name or View name to the variable Sheet_Name.
    If you want to load data from multiple sheets in multiple .xlsx files into a SQL Server table, please refer to following thread:
    http://stackoverflow.com/questions/7411741/how-to-loop-through-excel-files-and-load-them-into-a-database-using-ssis-package
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Error in cast multiset in collections

    DECLARE
    TYPE emp_dept_rec IS RECORD (
    v_sal emp.sal%TYPE,
    v_name emp.ename%TYPE,
    v_deptname dept.DEPTNAME%type
    TYPE emp_dept_tab_type IS TABLE OF emp_dept_rec;
    l_emp_dept_tab emp_dept_tab_type;
    type emp_tab is table of emp%rowtype;
    type l_emp_tab is table of emp%rowtype;
    type dept_tab is table of dept%rowtype;
    type l_dept_tab is table of dept%rowtype;
    cursor e1 is
    select * from emp;
    cursor d1 is select * from dept;
    begin
    OPEN e1;
    FETCH e1
    BULK COLLECT INTO l_emp_tab;
    open d1;
    FETCH d1
    BULK COLLECT INTO l_dept_tab;
    select cast(multiset (select em.sal,em,ename ,dep.DEPTNAME
    from table(l_emp_tab) em,table(l_dept_tab) dep
    where em.deptno=dep.deptno)
    as emp_dept_tab_type)
    into l_emp_dept_tab ;
    end;
    it is giving error as
    ORA-06550: line 43, column 25:
    PL/SQL: ORA-00923: FROM keyword not found where expected
    ORA-06550: line 39, column 5:
    PL/SQL: SQL Statement ignored

    Here is an example.
    SQL> CREATE OR REPLACE TYPE emp_rec IS OBJECT (
      2                      v_sal    NUMBER(7,2),
      3                      v_name   VARCHAR2(35),
      4                      v_empno  NUMBER(4),
      5                      v_deptno NUMBER(2)
      6                      )
      7  ;
      8  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_tab IS TABLE OF emp_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_rec IS OBJECT (
      2                      v_deptno NUMBER,
      3                      v_dname VARCHAR2(50)
      4                      )
      5  ;
      6  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_tab IS TABLE OF dept_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_rec IS
      2                     OBJECT (
      3                      v_sal     NUMBER,
      4                      v_name     VARCHAR2(35),
      5                      v_deptname VARCHAR2(30)
      6                      );
      7  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_tab_type IS TABLE OF emp_dept_rec;
      2  /
    Type created.
    SQL> set serverout on
    SQL> DECLARE
      2    l_emp_dept_tab emp_dept_tab_type; --emp_dept_tab_type declared in database
      3    l_emp_tab      emp_tab; --emp_tab declared in database
      4    l_dept_tab     dept_tab; --dept_tab declared in database
      5 
      6    CURSOR e1 IS
      7      SELECT emp_rec(sal, ename, empno, deptno) FROM emp; --Note the type casting here
      8 
      9    CURSOR d1 IS
    10      SELECT dept_rec(deptno, dname) FROM dept; --Note the type casting here
    11  BEGIN
    12    OPEN e1;
    13 
    14    FETCH e1 BULK COLLECT
    15      INTO l_emp_tab;
    16 
    17    OPEN d1;
    18 
    19    FETCH d1 BULK COLLECT
    20      INTO l_dept_tab;
    21 
    22    SELECT CAST(MULTISET (SELECT em.v_sal, em.v_name, dep.v_dname
    23                   FROM TABLE(l_emp_tab) em, TABLE(l_dept_tab) dep
    24                  WHERE em.v_deptno = dep.v_deptno) AS emp_dept_tab_type)
    25      INTO l_emp_dept_tab
    26      FROM DUAL;
    27    FOR i IN 1 .. l_emp_dept_tab.COUNT LOOP
    28      dbms_output.put_line(l_emp_dept_tab(i)
    29                           .v_sal || '--' || l_emp_dept_tab(i)
    30                           .v_name || '--' || l_emp_dept_tab(i).v_deptname);
    31    END LOOP;
    32 
    33  END;
    34  /
    1300--MILLER--ACCOUNTING
    5000--KING--ACCOUNTING
    2450--CLARK--ACCOUNTING
    3000--FORD--RESEARCH
    1100--ADAMS--RESEARCH
    3000--SCOTT--RESEARCH
    2975--JONES--RESEARCH
    800--SMITH--RESEARCH
    950--JAMES--SALES
    1500--TURNER--SALES
    2850--BLAKE--SALES
    1250--MARTIN--SALES
    1250--WARD--SALES
    1600--ALLEN--SALES
    PL/SQL procedure successfully completed.It is just for educational purpose, because the thing you have achieved by so much programming can be done easily by simple join in the table itself.
    user10447332 Newbie
    Handle: user10447332
    Status Level: Newbie
    Registered: Oct 20, 2008
    Total Posts: 227
    Total Questions: 153 (152 unresolved) >
    What a record! and most of the time you don't care to follow/revisit the thread also!.

  • Error in cast to MULTIPART

    Hi, I test the follow Jguru tutorial code for getting atacchements
    Multipart multipart = (Multipart)message.getContent();
    for (int i=0, n=multipart.getCount(); i<n; i++) {
    Part part = multipart.getBodyPart(i));
    String disposition = part.getDisposition();
    if ((disposition != null) &&
    ((disposition.equals(Part.ATTACHMENT) ||
    (disposition.equals(Part.INLINE))) {
    saveFile(part.getFileName(), part.getInputStream());
    But i have a problem of cast in this line
    Multipart mp = (Multipart)message.getContent();
    the error of CastClass is:
    java.lang.String cannot be cast to javax.mail.Multipart
    why????? Please help me
    Thanks

    Most likely you don't have a multipart message. See the msgshow.java
    demo program that comes with JavaMail.

  • Could not type cast in java embedding

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    org.xml.sax.InputSource in = (org.xml.sax.InputSource) getVariableData("Invoke_1_getRoutingAndFrameJumpers_OutputVariable","getRoutingAndFrameJumpersResponse");
    Document doc = db.parse(in);
    In the above code I am trying to type cast the variable getRoutingAndFrameJumpersResponse into org.xml.sax.InputSource so that i can parse.
    I am not getting any error during compilation
    but I am unable to type cast some run time error is coming in the line were I am type casting but I am not able to see the runtime error.
    How can I see the runtime error in java embedding, how to type cast a variable into xml so that I can parse it.

    Hi Arun,
    Could you try using the bpelx:rename extension in an assign activity enables a BPEL process to rename an element through use of XSD type casting.
    <bpel:assign>
    <bpelx:rename elementTo="QName1"? typeCastTo="QName2"?>
    <bpelx:target variable="ncname" part="ncname"? query="xpath_str" />
    </bpelx:rename>
    </bpel:assign>
    Cheers
    A

  • Derive found flag in SQL with where clause using TABLE(CAST function

    Dear All,
    Stored procedure listEmployees
    ==========================
    CREATE OR REPLACE TYPE STRING_ARRAY AS VARRAY(8000) OF VARCHAR2(15);
    empIdList STRING_ARRAY
    countriesList STRING_ARRAY
    SELECT EMP_ID, EMP_COUNTRY, EMP_NAME, FOUND_FLAG_
    FROM EMPLOYEE WHERE
    EMP_ID IN
    (SELECT * FROM TABLE(CAST(empIdList AS STRING_ARRAY))
    AND EMP_COUNTRY IN
    (SELECT * FROM TABLE(CAST(countriesList AS STRING_ARRAY))
    =================
    I have a stored procedure which lists the employees using above simple query.
    Here I am using table CAST function to find the list of employees in one go
    instead of looping through each and every employee
    Everything fine until requirements forced me to get the FOUND_FLAG as well.
    Now I wanted derive the FOUND_FLAG by using rownum, rowid, decode functions
    but I was not successful
    Can you please suggest if there is any intelligent way to say weather the
    row is found for given parameters in the where clause?
    If not I may have to loop through each set of empIdList, countriesList
    and find the values individually just to set a flag. In this approach I can’t use
    the TABLE CAST function which is efficient I suppose.
    Note that query STRING_ARRAY is an VARRAY. It is very big in size and this procedure
    suppose to handle large sets of data.
    Thanks In advance
    Regards
    Charan
    Edited by: kmcharan on 03-Dec-2009 09:55
    Edited by: kmcharan on 03-Dec-2009 09:55

    If your query returns results, you have found them... so your "FOUND" flag might be a constant,...

  • Casting in ABAP Objects

    Why the cast error generates only in Widening cast?

    Hi Shyam,
    WELCOME TO SDN!!!
    Please check this link
    http://abapprogramming.blogspot.com/2007/10/oops-abap-8.html
    The widening cast in this case does not cause an error because the reference airplane actually points to an instance in the subclass lcl_cargo_airplane. The dynamic type is therefore u2018REF TO lcl_cargo_airplaneu2019.
    Here the widening cast produces the MOVE_CAST_ERROR runtime error that can be caught with u201CCATCH ... ENDCATCHu201D, because the airplane reference does not point to an instance in the subclass lcl_cargo_airplane, but to a u201Cgeneral airplane objectu201D. Its dynamic type is therefore u2018REF TO lcl_airplaneu2019 and does not correspond to the reference type cargo_airplane.
    The widening cast logically represents the opposite of the narrowing cast. The widening cast cannot be checked statically, only at runtime. The Cast Operator u201C?=u201D (or the equivalent u201CMOVE ... ?TO u2026u201D) must be used to make this visible.
    With this kind of cast, a check is carried out at runtime to ensure that the current content of the source variable corresponds to the type requirements of the target variables. In this case therefore, it checks that the dynamic type of the source reference airplane is compatible with the static type of the target reference cargo_airplane. If it is, the assignment is carried out. Otherwise the catchable runtime error u201CMOVE_CAST_ERRORu201D occurs, and the original value of the target variable remains the same.
    Best regards,
    raam

  • Can not cast from object to int

    Hi All,
    I have the following bunch of code
    Session session;
              session = getSessionFactory().openSession();
              Query query;
              int MaxPageId = 0;
              List list;
              try{
                   query = session.createQuery("select max(emp.id) from EmpBean emp");
                   list = query.list();
                   MaxPageId = (int) list.get(0);
                   return MaxPageId;
              catch(Exception e){
                   System.out.println(e.getMessage());
              return MaxPageId;
    The query executed successfully but when i get the max id in a integer variable by the following statement
    MaxPageId = (int) list.get(0);
    I get the following error "can not cast from object to int"
    Please suggest for the same.
    -Thanks

    Cast to an Integer, not an int, and let autoboxing turn the Integer into an int.
    int maxPageId;
    maxPageId = (Integer) list.get(0);You can't cast objects into primitives.
    Autoboxing isn't casting.
    And use Java naming conventions. Local variables start with a lower-case letter.

  • How to cast a column of a derived column in a view to NULL

    I have a derived column in my view and this column by default is picked up as not null.
    I want to cast it to null how can i do it ?
    Actual column
    column1 varchar(3) not null
    Expected column
    column1 varchar(3)  null
    Mudassar

    Shridar I  havent defined it but the derived column has been picked up as not null which is strange
    CREATE VIEW test
    AS
    SELECT 
    CASE
    WHEN COMPANY_SIZE IS NULL then  'a'
    ELSE 'b' 
    END AS
    column1 ----- added derived column identifier
    ,[Company_Size] AS [CompanySize]
    FROM xyz
    Mudassar

Maybe you are looking for

  • Capturing elements value in the selection screen for LDB during run time

    Hi, I have a program where LDB is used. Could anyone please suggest how to capture the values of the elements present in the LDB's default selection screen. Specially, the company code and the period values. Please reply . Its too urgent. Regards, Bi

  • TIme Machine backing up an External Drive

    hello a problem that is really vexing me I had a 500gb ext hardrive for my itunes and then a 1TB harddrive for my time machine, both plugged in at all times, to my macbook due to the iTunes drive getting full I got a new 1TB drive for that (not the s

  • Usage / down load dashboard

    We have a requirement from our management team to getting a MIS sort of report about 1) List of documents accessed by a user 2) List of documents downloaded by a user 3) Within in given period of time how many documents where accessed/ downloaded and

  • Adding brushes to drop menu???

    I have just collected my favourite brushes and saved the set into my brushes folder as james'brushes.abr - i can load my brushes and use them now. But i cant figure out how to add them to my drop down menu... I've tried going to Menus... > Panel Menu

  • Issue getting template areas to align correctly

    Hello. This is my first post on the Adobe Support Forums and also my first time using Dreamweaver. I am only marginally proficient with basic HTML and have a limited understanding of CSS and Dreamweaver, so please forgive me for posting stupid questi