Link to home
Start Free TrialLog in
Avatar of itortu
itortuFlag for United States of America

asked on

assign dataset row value to function

i got just one more error in my program (well that is what i think)

i have this function:

Public Function GetStateByGeo(ByVal strGeo$) As DataSet

then i try to assign the dataset value to the function like this:

            If (Not IsNothing(ds)) Then
                If (ds.Tables(0).Rows.Count > 0) Then
                    GetStateByGeo = ds.Tables(0).Rows(0).ToString
                End If
            End If

but i get error:

Value of type 'System.Data.DataRow' cannot be converted to 'System.Data.DataSet'.      

how can the data set (recordset) can be assigned to the function ?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you want to return one row of the table or the whole table in the return dataset?
Avatar of itortu

ASKER

than yo for asking, i want to return one row fo the table
Avatar of itortu

ASKER

i tried your suggestion this way:

    Public Function GetStateByGeo(ByVal strGeo$) As DataSet

        Dim intGeoState As Integer
        Dim strSQL As String = ""
        Dim strFlag As String = ""
        Dim ds As DataSet = Nothing
        dim dr as DataRow

        Try

            intGeoState = CInt(Mid(strGeo, 1, 2))

            strFlag = GetTableFlag("LOCSTATE")

            strSQL = "SELECT * FROM LOCSTATE" & strFlag & " WHERE locgeostate = " & intGeoState

            ds = m_objSQLServerSQLDATA.GetDataSet(strSQL, CommandType.Text, 0)

            If (Not IsNothing(ds)) AndAlso ds.Tables(0).Rows.Count > 0 Then
                Return ds.Tables(0).Rows(0).ToString
            End If

        Catch ex As Exception

        Finally
            ds = Nothing
        End Try
        Return ds
    End Function


this is how the function gets called from another function:

ds = o_data.GetStateByGeo(strGeo)

now i get the error:

Value of type 'String' cannot be converted to 'System.Data.DataSet'.      

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itortu

ASKER

sorry this line

  Public Function GetStateByGeo(ByVal strGeo$) As DataSet

is actually
  Public Function GetStateByGeo(ByVal strGeo$) As string

the error:

Value of type 'String' cannot be converted to 'System.Data.DataSet'.      

is given now by this part:

ds = o_data.GetStateByGeo(strGeo)

Me.TextBox1.Text = o_Data.GetStateByGeo(strGeo)

Bob