itortu
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).ToStr ing
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 ?
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).ToStr
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you want to return one row of the table or the whole table in the return dataset?
ASKER
than yo for asking, i want to return one row fo the table
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.GetD ataSet(str SQL, CommandType.Text, 0)
If (Not IsNothing(ds)) AndAlso ds.Tables(0).Rows.Count > 0 Then
Return ds.Tables(0).Rows(0).ToStr ing
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(strGe o)
now i get the error:
Value of type 'String' cannot be converted to 'System.Data.DataSet'.
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.GetD
If (Not IsNothing(ds)) AndAlso ds.Tables(0).Rows.Count > 0 Then
Return ds.Tables(0).Rows(0).ToStr
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(strGe
now i get the error:
Value of type 'String' cannot be converted to 'System.Data.DataSet'.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(strGe o)
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(strGe
Me.TextBox1.Text = o_Data.GetStateByGeo(strGe o)
Bob
Bob