locked
Error - Dataset1 is a class type and cannot be used as an expression RRS feed

  • Question

  • User-797751191 posted

    Hi

      I am trying like below code . Secondly how i can retreive in GetData. Dataset1 is a dataset and CostingDataTable is a Datatable

    Call GetData("OrderNo",  DataSet1.CostingDataTable)

    Thanks

    Wednesday, September 4, 2019 4:57 PM

All replies

  • User475983607 posted

    jsshivalik

      I am trying like below code . Secondly how i can retreive in GetData. Dataset1 is a dataset and CostingDataTable is a Datatable

    Call GetData("OrderNo",  DataSet1.CostingDataTable)

    The syntax is incorrect.

    C#

    DataSet1.Tables["CostingDataTable"]

    VB

    DataSet1.Tables("CostingDataTable")

    I recommend reading the DataSet reference documentation rather than making up your own syntax.

    https://docs.microsoft.com/en-us/dotnet/api/system.data.dataset?view=netframework-4.8

    Wednesday, September 4, 2019 6:09 PM
  • User288213138 posted

    Hi jsshivalik,

    As all-star said, your  syntax is incorrect.

    The code:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim dt1 As DataTable = New DataTable("Table1")
        dt1.Columns.AddRange(New DataColumn(1) {New DataColumn("ID"), New DataColumn("Name")})
        dt1.Rows.Add(1, "Admin")
        Dim dt2 As DataTable = New DataTable("Table2")
        dt2.Columns.AddRange(New DataColumn(1) {New DataColumn("User"), New DataColumn("Role")})
        dt2.Rows.Add("CCC", "Admin")
        Dim ds As DataSet = New DataSet()
        ds.Tables.Add(dt1)
        ds.Tables.Add(dt2)
    
        If ds.Tables.Contains("Table2") Then
            Dim name As String = ds.Tables("Table2").TableName
            Response.Write(name)
        End If
    End Sub
    

    The result:

    Best regards,

    Sam

    Thursday, September 5, 2019 6:54 AM