Using System;
Using System. Data;
Using System. Data. SqlClient;
Namespace Demo3
{
/// <Summary>
/// Summary of Class1.
/// </Summary>
Class Class1
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main (string [] args)
{
//
// TODO: Add code here to start the application
Demo dm = new Demo ();
Dm. DoDemo ();
//
}
}
Class Demo
{
Public void DoDemo ()
{
DataSet ds = new DataSet ();
ExecuteOptions oExecute = new ExecuteOptions ();
Ds = oExecute. ExecuteandFill ();
// Display all sales transactions on the console
// An action query doesnt generate any results for processing
OExecute. ExecuteNonQuery ();
// Use the reader to walkthrough the results in a forward-only manner
OExecute. ExecuteReader ();
// Return the total number of sale transactions in the database
Int nSum = oExecute. ExecuteScalar ();
Console. WriteLine ("Record count is" + nSum. ToString ());
}
}
Class ExecuteOptions
{
Public SqlDataReader ExecuteReader ()
{
SqlConnection con = new SqlConnection ("Server = localhost; Integrated Security = SSPI; database = mydatabase; Max Pool Size = 75; Min Pool Size = 5 ");
SqlCommand privilege Title = new SqlCommand ("select Username, password, score from scoretable", con );
Repeated title. CommandType = CommandType. Text;
SqlDataReader dr;
Con. Open ();
Dr = titled title. ExecuteReader (CommandBehavior. CloseConnection );
Return dr;
}
Public int ExecuteScalar ()
{
SqlConnection con = new SqlConnection ("Server = localhost; Integrated Security = SSPI; database = mydatabase; Max Pool Size = 75; Min Pool Size = 5 ");
SqlCommand into titlecount = new SqlCommand ("select count (*) from scoretable", con );
Required titlecount. CommandType = CommandType. Text;
Con. Open ();
Return Convert. ToInt32 (effectitlecount. ExecuteScalar (). ToString ());
}
Public void ExecuteNonQuery ()
{
SqlConnection con = new SqlConnection ("Server = localhost; Integrated Security = SSPI; database = mydatabase; Max Pool Size = 75; Min Pool Size = 5 ");
SqlCommand cmdUpdateSales = new SqlCommand ("Update scoretable set score = score + 200 where username = 'Jackie Chan", con );
CmdUpdateSales. CommandType = CommandType. Text;
Con. Open ();
CmdUpdateSales. ExecuteNonQuery ();
}
Public DataSet ExecuteandFill ()
{
SqlConnection con = new SqlConnection ("Server = localhost; Integrated Security = SSPI; database = mydatabase; Max Pool Size = 75; Min Pool Size = 5 ");
SqlDataAdapter da = new SqlDataAdapter ("select username, password, score from scoretable", con );
DataSet ds = new DataSet ();
Con. Open ();
Da. Fill (ds );
Return ds;
}
}
}