Error: Value of type '1-dimensional array of System.Data.Dataset' cannot be converted

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marylipscomb
    New Member
    • Apr 2007
    • 51

    Error: Value of type '1-dimensional array of System.Data.Dataset' cannot be converted

    I am using VB.NET. I am trying to connect a button so that when it is clicked the gridview pops up the data.


    Partial Class Switchboard
    Inherits System.Web.UI.P age
    Protected Sub btnLookup_Load( ByVal sender As Object, ByVal e As System.EventArg s) Handles btnLookup.Load
    If Not Page.IsPostBack Then
    Dim queryString As String = "Select CompanyID As CompanyID, Company As Company, [City Location] As [City Location], [Invest Status] As [Invest Status], Phone As Phone, [Fist Name] + ' ' + [Last Name] As Contact From(Companies) "
    Dim ds As System.Data.Dat aSet = GetData(querySt ring)
    If (ds.Tables.Coun t > 0) Then
    GVCompany.DataS ource = ds
    GVCompany.DataB ind()
    Else
    lblMessage.Text = "Unable to connect to the database."

    End If

    End If
    End Sub
    Function GetData(ByVal queryString As String) As System.Data.Dat aSet()
    Dim ConnectionStrin g As String = ConfigurationMa nager.Connectio nStrings("Conne ctionString").C onnectionString
    Dim ds As New System.Data.Dat aSet()
    Try
    Dim connection As New System.Data.Sql Client.SqlConne ction(Connectio nString)
    Dim adapter As New System.Data.Sql Client.SqlDataA dapter(queryStr ing, connection)
    adapter.Fill(ds )
    Catch ex As Exception
    'Message.Text = "Unable to connect to the database."
    End Try
    Return ds
    Try

    Catch ex As Exception

    End Try
    End Function



    End Class


    The error I am getting is this :

    Value of type '1-dimensional array of System.Data.Dat aset'
    cannot be converted to 'System.Data.Da taset'.

    I am having so much trouble with this.. help would be so appreciated..

    thanks!!!!!
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Your function returns an array of dataset
    [code=vbnet]
    Function GetData(ByVal queryString As String) As System.Data.Dat aSet()
    [/code]

    Try this:
    [code=vbnet]
    Function GetData(ByVal queryString As String) As System.Data.Dat aSet
    [/code]

    Comment

    • marylipscomb
      New Member
      • Apr 2007
      • 51

      #3
      now I am getting this error when I go to the page.




      Object reference not set to an instance of an object.
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

      Exception Details: System.NullRefe renceException: Object reference not set to an instance of an object.

      Source Error:


      Line 18: End Sub
      Line 19: Function GetData(ByVal queryString As String) As System.Data.Dat aSet
      Line 20: Dim ConnectionStrin g As String = ConfigurationMa nager.Connectio nStrings("Conne ctionString").C onnectionString
      Line 21: Dim ds As New System.Data.Dat aSet
      Line 22: Try


      Source File: V:\inetpub\wwwr oot\WVDODevSite \Switchboard.as px.vb Line: 20

      Stack Trace:


      [NullReferenceEx ception: Object reference not set to an instance of an object.]
      Switchboard.Get Data(String queryString) in V:\inetpub\wwwr oot\WVDODevSite \Switchboard.as px.vb:20
      Switchboard.btn Lookup_Load(Obj ect sender, EventArgs e) in V:\inetpub\wwwr oot\WVDODevSite \Switchboard.as px.vb:8
      System.Web.UI.C ontrol.OnLoad(E ventArgs e) +99
      System.Web.UI.C ontrol.LoadRecu rsive() +47
      System.Web.UI.C ontrol.LoadRecu rsive() +131
      System.Web.UI.C ontrol.LoadRecu rsive() +131
      System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +1061




      --------------------------------------------------------------------------------
      Version Information: Microsoft .NET Framework Version:2.0.507 27.832; ASP.NET Version:2.0.507 27.832

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Is this the offending line?
        [code=vbnet]
        Dim ConnectionStrin g As String = ConfigurationMa nager.Connectio nStrings("Conne ctionString").C onnectionString
        [/code]

        Comment

        • marylipscomb
          New Member
          • Apr 2007
          • 51

          #5
          yes thats the problem

          Comment

          • marylipscomb
            New Member
            • Apr 2007
            • 51

            #6
            Dim ConnectionStrin g As String = ConfigurationMa nager.Connectio nStrings("Conne ctionString").C onnectionString




            is ("ConnectionStr ing") where I put my connection string??? for example it would look like this:

            Dim ConnectionStrin g As String = ConfigurationMa nager.Connectio nStrings
            (Data Source=MLIPSCOM B737; Initial Catalog=BID; Integrated Security = True.Connection String

            ???
            Thanks for all your help!!!!

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              No, that is where it is referencing the connectionstrin gs section of your web.config file.
              Do you have a connectionstrin g in there?

              Something like:
              Code:
              <connectionStrings>
                 <add name="myconstring" connectionString="Data Source=MLIPSCOMB737; Initial Catalog=BID; Integrated Security = True"/>
              </connectionStrings>
              then you would do:
              [code=vbnet]
              Dim ConnectionStrin g As String = ConfigurationMa nager.Connectio nStrings("mycon string").Connec tionString
              [/code]
              (I think)

              Comment

              Working...