See a post:SqlDataReader ShutdownEveryone seems confused about the link closure problem. Here we will explain it:
No matter what xxDataReader is, It inherits the implementation of DataReader, so there are commonalities, so the title is titled DataReader.
Case 1: The default link of DataReader is not closed.
Sample Code:Static void Main (string [] args)
{
SqlConnection con = new SqlConnection ("server =.; database = MySpace; uid = sa; pwd = 123456 ");
Con. Open ();
SqlCommand com = new SqlComm
Configure the database connection string in WebConfig. The Code is as follows:
Copy codeThe Code is as follows: Then obtain the connection string in Webform_1.aspx.cs and add the following reference;Copy codeThe Code is as follows: using System. Configuration;Using System. Data;Using System. Data. SqlClient;
Code:Copy codeThe Code is as follows: SqlConnection con;Protected void Page_Load (object sender, EventArgs e){ConnectDB ();}Private void ConnectDB (){String ConString = ConfigurationManager.
...
3. Finally, it is the provider. The program is actually a recursive algorithm.Private void getarticlecategory (string PID){Sqlconnection conn = new sqlconnection ("Server =.; database = test; uid = sa; Pwd = ;");String SQL = "select articlesgroup_id, groupname from articlesgroup where articlesgroup_parent_id = @ PID order by groupname ";Sqlcommand cmd = new sqlcommand (SQL, Conn );Sqlparameter pid = new sqlparameter ("@ PID", sqldbtype. INT );PID. value = PID;Cmd. Parameters. Add (PID );Con
To configure the database connection string in Webconfig, the code is as follows:
Copy Code code as follows:
Then get the connection string inside the Webform_1.aspx.cs to add the following reference;
Copy Code code as follows:
Using System.Configuration;
Using System.Data;
Using System.Data.SqlClient;
Code:
Copy Code code as follows:
SqlConnection con;
protected void Page_Load (object sender, EventArgs e)
{
Connectdb ();
", sqldbtype.nvarchar,1000),
New SqlParameter ("@PAGE_INDEX", sqldbtype.int,10),
New SqlParameter ("@PAGE_SIZE", sqldbtype.int,10),
New SqlParameter ("@ORDERTYPE", sqldbtype.int,2),
New SqlParameter ("@ANDWHERE", sqldbtype.varchar,1000),
New SqlParameter ("@ORDERFEILD", sqldbtype.varchar,100)
};
Parms[0]. Value = "*";//Get all fields
PARMS[1]. Value = pageindex;//Current page index
PARMS[2]. Value = 10;//Page size
PARMS[3]. Value = 0;//Ascending order
PARMS[4]. Value = "";//Condition
http://blog.csdn.net/idays021/article/details/49661855Class Program{private static string _connstr;static void Main (string[] args){_connstr = configurationmanager.connectionstrings["plmconnectionstring"]. ToString ();Sqldependency.start (_CONNSTR);//incoming connection string, initiating database-based snoopingUpdateGrid ();Console.read ();}private static void UpdateGrid (){using (SqlConnection connection = new SqlConnection (_CONNSTR)){Dependencies are based on a table, and the query statement
the database///////////////////////////////////////////////////////////* SqlCommand cmd = new Sqlcomm and ("SELECT * from Db_student", SC); SqlDataReader SDR = cmd. ExecuteReader (); Executes the Find record command while (SDR. Read ()) {Console.WriteLine ("{0}{1}{2}{3}", Sdr[0], sdr[1],
System. data. sqlClient; using System. linq; using System. text; using System. threading. tasks; namespace SQLTest {class Program {static void Main (string [] args) {// connect to the database string connection = "server = Pan Shang \ SQLEXPRESS; database = db_test; trusted_Connection = true "; SqlConnection SC = new SqlConnection (connection); // SC. connectionString = conne Ction; try {SC. Open (); // Open the database connection Console. WriteLine ("the database connection has been enabled!
Source:
Http://hi.baidu.com/kb81/blog/item/c8315f8236e85aa
Recently, a website requires an infinitely hierarchical drop-down list, so the following small works are available.
At first, I thought that the unlimited drop-down list function should be very simple. It is nothing more than a recursion.AlgorithmOkay,ProgramIt is actually a recursive algorithm.
Private
Void
Getarticlecategory (
String
PID)
{Sqlconnection Conn = New Sqlconnection ( " Server =.; database
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.