How to convert object[] to char[] ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tienlx

    How to convert object[] to char[] ?

    Hi all,
    I'm have a problem that i don't know how to convert object[] to char[]
    in C# .
    Does anybody know ?
    Thanks.

  • Jon Skeet [C# MVP]

    #2
    Re: How to convert object[] to char[] ?

    tienlx wrote:[color=blue]
    > I'm have a problem that i don't know how to convert object[] to char[]
    > in C# .
    > Does anybody know ?[/color]

    It would help if you'd give a bit of context - what's in your object[]?
    What do you want to get in your char[]? What's the overall purpose
    here?

    Jon

    Comment

    • tienlx

      #3
      Re: How to convert object[] to char[] ?

      Here is my code ( i want to get result from query that have FOR XML
      AUTO ):
      OleDbDataReader reader= cmd.ExecuteRead er();

      reader.Read();
      object[] arObj = new object[reader.FieldCou nt];
      int i = reader.GetValue s(arObj);


      Jon Skeet [C# MVP] viết :[color=blue]
      > tienlx wrote:[color=green]
      > > I'm have a problem that i don't know how to convert object[] to char[]
      > > in C# .
      > > Does anybody know ?[/color]
      >
      > It would help if you'd give a bit of context - what's in your object[]?
      > What do you want to get in your char[]? What's the overall purpose
      > here?
      >
      > Jon[/color]

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: How to convert object[] to char[] ?

        tienlx wrote:[color=blue]
        > Here is my code ( i want to get result from query that have FOR XML
        > AUTO ):
        > OleDbDataReader reader= cmd.ExecuteRead er();
        >
        > reader.Read();
        > object[] arObj = new object[reader.FieldCou nt];
        > int i = reader.GetValue s(arObj);[/color]

        Ah, I see. So, have you looked at what's inside arObj? What are the
        values? Are they strings? I suspect they are, but I wouldn't like to
        say for sure - just have a look.

        Jon

        Comment

        • Peter Bromberg [C# MVP]

          #5
          Re: How to convert object[] to char[] ?

          OK, well at this point you now have an object array containing all the column
          values of that row of the DataReader.

          Are you saying you now need to convert each object in the array to type
          char[]?
          e.g.
          char[] chAr=(char[])arObj[0];

          ?
          Peter
          --
          Co-founder, Eggheadcafe.com developer portal:

          UnBlog:





          "tienlx" wrote:
          [color=blue]
          > Here is my code ( i want to get result from query that have FOR XML
          > AUTO ):
          > OleDbDataReader reader= cmd.ExecuteRead er();
          >
          > reader.Read();
          > object[] arObj = new object[reader.FieldCou nt];
          > int i = reader.GetValue s(arObj);
          >
          >
          > Jon Skeet [C# MVP] viết :[color=green]
          > > tienlx wrote:[color=darkred]
          > > > I'm have a problem that i don't know how to convert object[] to char[]
          > > > in C# .
          > > > Does anybody know ?[/color]
          > >
          > > It would help if you'd give a bit of context - what's in your object[]?
          > > What do you want to get in your char[]? What's the overall purpose
          > > here?
          > >
          > > Jon[/color]
          >
          >[/color]

          Comment

          • tienlx

            #6
            Re: How to convert object[] to char[] ?

            I see in arObj[0],arObj[1]... is a number maybe char code. And my goal
            is convert arObj to a string. Or how i can to get data from query that
            have "FOR XML AUTO" ?
            Thanks.

            Peter Bromberg [C# MVP] viết :[color=blue]
            > OK, well at this point you now have an object array containing all the column
            > values of that row of the DataReader.
            >
            > Are you saying you now need to convert each object in the array to type
            > char[]?
            > e.g.
            > char[] chAr=(char[])arObj[0];
            >
            > ?
            > Peter
            > --
            > Co-founder, Eggheadcafe.com developer portal:
            > http://www.eggheadcafe.com
            > UnBlog:
            > http://petesbloggerama.blogspot.com
            >
            >
            >
            >
            > "tienlx" wrote:
            >[color=green]
            > > Here is my code ( i want to get result from query that have FOR XML
            > > AUTO ):
            > > OleDbDataReader reader= cmd.ExecuteRead er();
            > >
            > > reader.Read();
            > > object[] arObj = new object[reader.FieldCou nt];
            > > int i = reader.GetValue s(arObj);
            > >
            > >
            > > Jon Skeet [C# MVP] viết :[color=darkred]
            > > > tienlx wrote:
            > > > > I'm have a problem that i don't know how to convert object[] to char[]
            > > > > in C# .
            > > > > Does anybody know ?
            > > >
            > > > It would help if you'd give a bit of context - what's in your object[]?
            > > > What do you want to get in your char[]? What's the overall purpose
            > > > here?
            > > >
            > > > Jon[/color]
            > >
            > >[/color][/color]

            Comment

            Working...