Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Guys I wanted to as if there is a C# alterative or equivalent to Java's

Resultset Object and the getStatemnt function in the Resultset Object.

Java
	/**
	 * Function to close the statement object of the result set passed
	 * @param ResultSet Result Set Object
	 */
protected void closeStatement(ResultSet lObjResultSet) 
{
  try
  {
     if(lObjResultSet != null)
      {
	Statement objStatement = lObjResultSet.getStatement();
	if(objStatement != null)
        objStatement.close();
      }
  } catch(Exception e) 
    {
       System.out.println("Exception in closeStatement 2 of TransactionObject " +e.getMessage());
		}
} //end of function closeStatement


I am trying to convert this piece of code from java to c#

Thnks for your help.
Posted
Updated 24-Oct-13 8:17am
v2
Comments
Please explain the scenario and what you want to achieve.
rudolph098 24-Oct-13 14:18pm    
I have updated the question. Thank you

SqlDataReader is the equivalent of ResultSet

More Info -http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx[^]

Just close the database connection instance after execution of sql command. There is no such equivalent for getStatement
 
Share this answer
 
v3
Comments
rudolph098 24-Oct-13 14:48pm    
thank you, but something confuses me, in the code I placed above, they are passing a result set to an instance of a Statement object to be executed. So I am not sure how I will be able to mirror this with an SqlReader. Because an SqlReader get the data from an executed sqlcommand. I am confused , I would b very greatful if you shed more light on it. Thanks
Ranjan.D 24-Oct-13 14:52pm    
I suggestion not to duplicate , but understand the logic and do the same in C#.. Have a look into http://msdn.microsoft.com/en-us/library/haa3afyz.aspx in order to Retrieve Data Using a DataReader.
rudolph098 24-Oct-13 15:12pm    
my problem is that they Resltset passes the data to be executed to statement, but Datareader get the data from an exectuted SqlCommand. but there's is a reverse
Ranjan.D 24-Oct-13 15:16pm    
That's the reason I said though Java, C# look alike there are lots of differences. All you need to do in C# is create a connection object, command object and set the sql query to execute then execute the command so you will get a datareader , finally process the reader. It can be done with in 8 lines of code.
rudolph098 24-Oct-13 15:33pm    
ok so you said that a DataReader is Equivalent to a result set. So from the code, if a statement executes a Resultst, does an Sqlcommand execute a DataReader?
There is another version of the ResultSet I guess - the DataSet. These two are not identical though.
Some comparison here[^].

Forward Readonly restrictions do not exist in a DataSet.
 
Share this answer
 
v2

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