How to retrieve data from database for a particular period(ie..ex:jun 2006 to nov2006) using C#

Showing Answers 1 - 3 of 3 Answers

//Check the following example. I am using Orders table of Northwind database from SQL server.

public Dataset MyFunction()

{

SqlConnection objConnection = new SqlConnection(ConnectionString)

SqlCommand objCommand = null;

SqlDataAdapter objAdapter = null;

DataSet objDataSet = new DataSet ();

try

{

//Open the connection

objConnection.Open();

strQuery = "select * from orders where orderdate between '1996-07-04 00:00:00.000' and '1996-11-26 00:00:00.000'";

objCommand = new SqlCommand(strQuery, objConnection);

objAdapter = new SqlDataAdapter(objCommand);

objAdapter.Fill(objDataSet);

return objDataSet;

}

catch (Exception exc)

{

new Exception(exc.Message, exc);

return null;

}

finally

{

//Closes the connection

objConnection.Close();

if (objCommand != null)

{

objCommand = null;

}

if (objAdapter != null)

{

objAdapter = null;

}

}

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions