Public member 'Value' on type 'String' not found. Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sep410
    New Member
    • Jul 2008
    • 77

    Public member 'Value' on type 'String' not found. Error

    Hi all,
    Here is the code that I have:


    Code:
     For h = 2 To dt.Rows.Count - 1
                    For j = 0 To 11
    
                        Excel.Cells(h, k).value = (dt.Rows(h).Item(j).Value).ToString
                        k += 1
                    Next
                Next

    I get this error:
    Public member 'Value' on type 'String' not found.

    What should I do?
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Well, it seems like dt.Rows(h).Item (j) is a string. Strings don't have a property called value. So you don't need that or the .ToString part, which you are doing incorrectly anyway. ToString is a method, and must be called as such:
    .ToString()

    Hope that helps.

    Also, I noticed that you don't show where you initialize "k". Your loop variables are h and j, where does k come from?

    Comment

    • Sep410
      New Member
      • Jul 2008
      • 77

      #3
      Thanks,
      Now I have another problem. One of my columns contains system’s Id which starts it 08- .for example:08-1 or 08-25.

      This columns in excel will be shown as date and it will be 1-Aug or 25-Aug.

      What can I do?

      Comment

      • Sep410
        New Member
        • Jul 2008
        • 77

        #4
        editing datatable effects datagrid's value??

        In the same code I have to get the value for datatable from datagrid:
        dt = dg.DataSource
        And I need to edit dt to export it to excel but I don’t want my datagrid’s content to have the same changes.right now all the changes that I apply to dt is effected datagrid too.

        How can I stop that?

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          As to the first question, I can't help much because I don't have any experience programming for Excel. But I'm sure there is a way to set a column data type.

          As to the second, you need to learn a bit about Object Oriented Programming. When you reference an object, you aren't creating a copy of that object, you are passing a pointer to that object. Very efficient and useful, but it can have unintended consequences if you don't know about it.

          You need to use the .Clone() method of the DataTable, and then copy the rows across.

          Comment

          • Sep410
            New Member
            • Jul 2008
            • 77

            #6
            Originally posted by insertAlias
            As to the first question, I can't help much because I don't have any experience programming for Excel. But I'm sure there is a way to set a column data type.

            As to the second, you need to learn a bit about Object Oriented Programming. When you reference an object, you aren't creating a copy of that object, you are passing a pointer to that object. Very efficient and useful, but it can have unintended consequences if you don't know about it.

            You need to use the .Clone() method of the DataTable, and then copy the rows across.
            Thanks for the help.
            I should learn about it.

            Comment

            • Sep410
              New Member
              • Jul 2008
              • 77

              #7
              I tried .Clone() but I still have sace problem!

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                Are you sure you are using it right? Post that part of your code.

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  Are you doing:
                  dt = dg.DataSource.C lone()
                  ???

                  Comment

                  Working...