Click here to Skip to main content
15,886,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public static Hashtable ExecuteHashTable(SqlConnection connection, CommandType commandType, string commandText)
{
System.Data.SqlClient.SqlDataReader oDataReader = default(System.Data.SqlClient.SqlDataReader);
Hashtable oHashTable = new Hashtable();
oDataReader = ExecuteReader(connection, commandType, commandText, (SqlParameter[])null);
while (oDataReader.Read())
{
oHashTable.Add(oDataReader.Item[0].ToString().Trim, oDataReader.Item[1].ToString().Trim);
}
oDataReader.Close();
return oHashTable;
}
Posted
Updated 17-Jul-14 22:45pm
v2
Comments
nilesh sawardekar 18-Jul-14 2:16am    
which problem your facing in this..please mention
Sathish kumar M S 18-Jul-14 2:21am    
in this below line
oHashTable.Add(oDataReader.Item[0].ToString().Trim, oDataReader.Item[1].ToString().Trim);
ArunRajendra 18-Jul-14 4:46am    
what the problem in this line.
Sathish kumar M S 18-Jul-14 4:49am    
Error 62 'System.Data.SqlClient.SqlDataReader' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.Data.SqlClient.SqlDataReader' could be found (are you missing a using directive or an assembly reference?)
Sathish kumar M S 18-Jul-14 4:50am    
error msg showing like this

Hi Try to write Items at the place of Item.

HashTable.Add(oDataReader.Items[0].ToString().Trim, oDataReader.Items[1].ToString().Trim);
 
Share this answer
 
Comments
Sathish kumar M S 18-Jul-14 4:53am    
showing same error message
Sathish kumar M S 18-Jul-14 4:55am    
actually I converted code from vb.net to c#
my vb.net code is
Public Overloads Shared Function ExecuteHashTable(ByVal connection As SqlConnection, _
ByVal commandType As CommandType, _
ByVal commandText As String) As Hashtable
Dim oDataReader As System.Data.SqlClient.SqlDataReader
Dim oHashTable As New Hashtable()
oDataReader = ExecuteReader(connection, commandType, commandText, CType(Nothing, SqlParameter()))
Do While oDataReader.Read
oHashTable.Add(CStr(oDataReader.Item(0)).Trim, CStr(oDataReader.Item(1)).Trim)
Loop
oDataReader.Close()
Return oHashTable
End Function
Ranjeet Patel 18-Jul-14 5:30am    
Try this link
http://forums.asp.net/t/1601495.aspx?+CS1061+System+Data+SqlClient+SqlDataReader+does+not+contain+a+definition+for+Item+and+no+extension+method+Item+accepting+a+first+argument+of+type+System+Data+SqlClient+SqlDataReader+could+be+found+are+you+missing+a+using+directive+or+an+assembly
oHashTable.Add(oDataReader.ToString()[0], oDataReader.ToString()[1]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900