Solved

Value of type 'String' cannot be converted to '1-dimensional array of String'.

Posted on 2009-05-18
7
540 Views
Last Modified: 2013-11-07
i need to get the date from this array , so i created a function for to retreive , but the problem i dunno how to convert the gridview cell to array , hence i get this error,
Value of type 'String' cannot be converted to '1-dimensional array of String'.  ,
in this line ..
   Dim arrdb() As String =  e.Row.Cells(0).Text.Tostring()

date2 column in db it  is stored like this ,
da#dasdasdda#05/05/2009,dasd#dasdasdd#05/06/2009
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Style="">
            <Columns>
            <asp:BoundField DataField="date2"/>
            </Columns>
        </asp:GridView>
 
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim arrdb() As String =  e.Row.Cells(0).Text.Tostring()
//error line
            Dim date2 As DateTime = arryfun(arrdb)
    End If
    End Sub
 Private Function arrfun(ByVal ds() As String) As String
        Dim dbdat As String = ""
        Dim in1 As Integer = 1
        For Each arr As String In ds.ToString().Split(",")
            If in1 = 2 Then
                Dim vals1() As String = arr.Split("#")
                If vals1.Length > 2 Then
                    dbdat = vals1(2).ToString()
                    Exit For
                End If
            End If
            in1 = in1 + 1
        Next
        Return dbdat
    End Function

Open in new window

0
Comment
Question by:Rajar Ahmed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 24412686
You're trying to set a String array equal to a string. That's what it is complaining about.

Instantiate the array and then set

arrdb(0) =  e.Row.Cells(0).Text.Tostring()

and it should be fine.

0
 
LVL 9

Expert Comment

by:CyberLex
ID: 24412689
e.Row.Cells(0).Text.Tostring()
this does probably not return a string array but a single string value
0
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 24412769
btw did you know you can get all your cells into an array with one line of code?


e.Row.Cells.CopyTo(YourArrayInstance)

Open in new window

0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24412800
i get this error,
Dim arrdb() As String
arrdb(0) =  e.Row.Cells(0).Text.Tostring()
Object reference not set to an instance of an object.

wat this line means ...how can i implement in the code ,
e.Row.Cells.CopyTo(YourArrayInstance)
0
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 24412894
Dim arrdb() As String = e.Row.Cells(0).Text.Tostring()

Or you could do;

Dim arrdb(e.Row.Cells.Count) As String
e.Row.Cells.CopyTo(arrdb)

0
 
LVL 32

Accepted Solution

by:
Jamie McAllister MVP earned 500 total points
ID: 24412987
I think I typo-ed!!

Dim arrdb() As String = {e.Row.Cells(0).Text.Tostring()}
0
 
LVL 3

Expert Comment

by:channa_m
ID: 24416273
You can replace your line
 Dim arrdb() As String =  e.Row.Cells(0).Text.Tostring()

with the following code
  Dim cellText As String
    cellText = e.Row.Cells(0).Text.Tostring()
   Dim arrdb() As String = {cellText}

Open in new window

0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question