[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 544
  • Last Modified:

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

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
Rajar Ahmed
Asked:
Rajar Ahmed
1 Solution
 
Jamie McAllister MVPArchitectCommented:
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
 
CyberLexCommented:
e.Row.Cells(0).Text.Tostring()
this does probably not return a string array but a single string value
0
 
Jamie McAllister MVPArchitectCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Rajar AhmedConsultantAuthor Commented:
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
 
Jamie McAllister MVPArchitectCommented:
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
 
Jamie McAllister MVPArchitectCommented:
I think I typo-ed!!

Dim arrdb() As String = {e.Row.Cells(0).Text.Tostring()}
0
 
channa_mCommented:
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now