A good Demo

Source: Internet
Author: User
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;
}
}

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.