|
-
Jun 21st, 2004, 06:33 AM
#1
Thread Starter
Hyperactive Member
Collections or Hashtables
From my DLL, I want to return some value in this format ...
test("Error",0)
test("Run",1)
and some more ....
which one should I use ... Collections or Hashtables ?
Also, right now I am returning hashtable from my DLL to form, and at the form side, I have declared a hashtable to take this return value in, but its always showing it as nothing for some reason, it returns the value from the DLL but on form side it becomes nothing automatically ????
-
Jun 21st, 2004, 07:20 AM
#2
Time to see some code.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 21st, 2004, 10:06 AM
#3
Thread Starter
Hyperactive Member
what code ? I just want to be able to return some keys and values associated with them ... I tried using array of System.Collections.DictionaryEntry, it worked. Just do not know which one is the preffered choice and why ?
-
Jun 23rd, 2004, 05:07 AM
#4
Hyperactive Member
The choice really depends on how you wish to access the data.
If it is to be more of a lookup table, ie you will be interrogating the data mainly by it's "key" value, or id you kust want to look at individual records based on the key value then I would suggest the hashtable.
If you mainly wish to retreive all the data every time with a for each...loop (for example) then the simple collection will be fine.
-
Jun 23rd, 2004, 10:57 AM
#5
Thread Starter
Hyperactive Member
Finally, I used Hashtables, work fine.
-
Jun 24th, 2004, 04:54 AM
#6
What about a dataset?
When should u use either a collection, hashtable or a dataset?
Woof
-
Jun 24th, 2004, 05:08 AM
#7
Originally posted by Wokawidget
What about a dataset?
When should u use either a collection, hashtable or a dataset?
Woof
That's a little overboard. DataSets would be most suited when working with a database or an XML data source.
I guess a hashtable is just like a collection, excepting that it is faster to search in.
-
Jun 24th, 2004, 06:28 AM
#8
Thread Starter
Hyperactive Member
Originally posted by Wokawidget
What about a dataset?
When should u use either a collection, hashtable or a dataset?
Woof
Yes, mendhak is right, dataset will be more like a overhead in this situation. Hashtables are just like collections, only they are better (I think) as far as speed is concerned.
-
Jun 24th, 2004, 06:35 AM
#9
So you would use these in the UI and not in the backend to pass data back to the UI???
Eh?
When running .NET and I come to a break point in my code, why can't I see the form1? As soon as it goes into the .NET IDE then the active form goes all white and I can't see anything on it.
Is this correct? Bad .NET IDE *slap*
-
Jun 24th, 2004, 06:56 AM
#10
Thread Starter
Hyperactive Member
Originally posted by Wokawidget
So you would use these in the UI and not in the backend to pass data back to the UI???
Eh?
When running .NET and I come to a break point in my code, why can't I see the form1? As soon as it goes into the .NET IDE then the active form goes all white and I can't see anything on it.
Is this correct? Bad .NET IDE *slap*
I have written a generic DLL component for Data Access with SQL Server based on Microsoft Standards and best practices. Now, there is this function called ExecuteStoredProcedure. This is a overloaded SP and can return either DataSet or DataTable for the results of a SP. But if SP has some output parameters too, then I need a way to return those Output paramters/values to UI too. They can not be part of DataSet or DataTable.
So I did something like this ...
ExecSP(ObjectToReturn as Object, blah blah) as Hashtable
if typename(ObjectToReturn ) is Dataset then return dataset
if typename(ObjectToReturn ) is Datatable then return Datatable
for each output parameter and if there is an @RETURN_VALUE parameter from SP too, I built a hashtable, add all those things to hashtable with there name, add one more item called "Error" pass it 0 if there was successfully execution of SP otherwise pass 1. This way my UI can not only get the SP data but also output parameters (if there were any).
-
Jun 24th, 2004, 06:57 AM
#11
Thread Starter
Hyperactive Member
Here's one method code ..
VB Code:
Public Overloads Function ExecuteStoredProcedure(ByVal connection As SqlConnection, ByVal storedProcedureName As String, _
ByRef returnObject As Object, ByVal sqlParameters() As SqlParameter, _
Optional ByVal includeReturnValue As Boolean = True, _
Optional ByVal mustCloseConnection As Boolean = False) As Hashtable
Dim i, j As Int16
Dim dataAdapter As New SqlDataAdapter
Dim returnValues As New Hashtable(New CaseInsensitiveHashCodeProvider, New CaseInsensitiveComparer)
Try
OpenConnection(connection)
Dim command As New SqlCommand(storedProcedureName, connection)
command.CommandType = CommandType.StoredProcedure
If Not (sqlParameters Is Nothing) Then
For i = 0 To CType(sqlParameters.Length - 1, Short)
command.Parameters.Add(sqlParameters(i))
Next
End If
If includeReturnValue Then
Dim returnValue As New SqlParameter("@RETURN_VALUE", SqlDbType.BigInt)
returnValue.Direction = ParameterDirection.ReturnValue
command.Parameters.Add(returnValue)
End If
dataAdapter.SelectCommand = command
If TypeName(returnObject).ToUpper = ("DataSet").ToUpper Then
dataAdapter.Fill(CType(returnObject, DataSet))
ElseIf TypeName(returnObject).ToUpper = ("DataTable").ToUpper Then
dataAdapter.Fill(CType(returnObject, DataTable))
Else
command.ExecuteNonQuery()
returnObject = Nothing
End If
returnValues.Add("Error", 0)
If includeReturnValue Then
returnValues.Add("@RETURN_VALUE", command.Parameters("@RETURN_VALUE").Value)
End If
Dim sqlParameter As SqlParameter
For Each sqlParameter In command.Parameters
If sqlParameter.Direction = ParameterDirection.InputOutput Or sqlParameter.Direction = ParameterDirection.Output Then
returnValues.Add(sqlParameter.ParameterName.ToString, sqlParameter.Value)
End If
Next
Return (returnValues)
Catch sqlex As SqlException
returnValues.Add("Error", 1)
LogException(sqlex)
Catch ex As Exception
returnValues.Add("Error", 1)
LogException(ex)
Finally
dataAdapter.Dispose()
If mustCloseConnection Then CloseConnection(connection)
End Try
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|