Avatar of itortu
itortu
Flag 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 ?
Visual Basic.NET.NET ProgrammingProgramming Languages-Other

Avatar of undefined
Last Comment
Bob Learned

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
divinewind80

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CmdoProg2

Do you want to return one row of the table or the whole table in the return dataset?
itortu

ASKER
than yo for asking, i want to return one row fo the table
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'.      

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
CmdoProg2

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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)

Bob Learned

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

Bob