Com.joybase.DB's source code (1)

Source: Internet
Author: User
Tags command line config dsn visual studio
source code using System;
Using System.Collections;
Using System.Data;
Using System.Globalization;
Using System.ComponentModel;
Using System.Drawing.Design;
Using System.Windows.Forms.Design;
Namespace Com.joybase.DB
{
<summary>
<b> assembly Name: Com.joybase.DB.dll (development version) </b><br/>
Version number: 1.4.0.0 (for VS. NET Official edition);<br/>
Developer:: Happy is good <br/>
</summary>
<remarks>
<b> e-Mail:</b>joy@china.com<br/>
<b> website: </b>http://www.joycode.com (opened in 2001/12/1) <br/>
Feature List
This assembly by <font color= "Red" ><b> happy good </b></font> development, if you encounter any doubt in use, you can <a href= "joy@china.com "> Letter Feedback </a&gt, thank you very much, please give a detailed description of the code snippets and errors in the letters!" <br/>
Database operation class, the effect has:<br/>
1. Databases that can be supported across any ado.net (already supported, tested data with MS Access as well as Ms SQLServer2000, and Oracle8i series) <br/>
2. Can execute stored procedure and normal SQL statement; (already supported) <br/>
3. Can get the value of the stored procedure return and export parameters; (already supported) <br/>
4. Simple to achieve paging effect (dataset already supported, DataReader supported) <br/>
5. Can be in DataSet, DataReader, DataTable and no results output;<br/>
6. transaction batch function (temporarily not supported) <br/>
7. Will support System.Data.ODBC Drive (temporarily not supported) <br/>
<div align= "center" ><b> Update list (1.3.0.1) </b></div>
1. Added a Joybasedbexception exception class that allows users to catch exceptions themselves <br/>
The reason property of the 2.JoyBaseDBException exception class can refer to the error cause of the current exception <br/>
3. Updated part of the example <br/>
4. This upgrade is specially crafted by the "blue" request, which is expressed thanks to;<br/>
<div align= "center" ><b> Update list (1.3.0.0) </b></div><br/>
1. Modified the original method of construction, adding the parameterless structure, eliminating the original method of single parameter construction;<br/>
2. A new addition of two properties, namely Connectionsetname, is equivalent to the single entry in the original constructor method, that is, the key name of the connection string in the config file, and the ConnectionString, which can be directly assigned to the database connection string. If this key is assigned, it will overwrite the original connectionstringsetname;<br/>
3. Modified the original executedatatable of the bug;<br/>
4. Modified the previous version of the two paging method, the out type parameter extraction as a property;<br/>
5. Some of the other small bugs inside
<div align= "center" ><b> Update list (1.2.0.3) </b></div><br/>
1. Removed the original Execute method and decomposed it into multiple methods;<br/>
2. Remove the ReturnType attribute and the Resulttype enumeration type. <br/>
3. Added the Executenoresult method, the return value is the record influence number;<br/>
4. Add the Executedatatable method, return a System.Data.DataTable, the name of the table defaults to "table" <br/>
5. Add the Executedatareader method, return a System.Data.IDataReader object <br/>
6. Overloaded Executedatareader method, support pagination display, parameter list is <br/>
Executedatareader (int pagesize,int currentpage,out int pagecount,out int PageSize) <br/>
PageSize: The number of records displayed per page;<br/>
CurrentPage the page number to be returned;<br/>
PageCount: Callback, returns the total number of pages;<br/>
PageSize: Back up, return the total number of records;<br/>
7. Added the ExecuteDataset method, and has four overloads, respectively, is <br/>
(1) ExecuteDataset () <br/>
Returns a system.data.dataset<br/>
(2) ExecuteDataset (string tablename);<br/>
The entry parameter is the name of the table;<br/>
(3) ExecuteDataset (string tablename,int startrecord,int Maxrecord);<br/>
Returns a total of Maxrecord records from the beginning of the record of article Startrecord. <br/>
(4) ExecuteDataset (string tablename,int pagesize,int currentpage,out int pagecount,out int RecordCount) <br/>
See the narration about the DataReader paging method. <br/>
///
</remarks>
<example>
///
Note: Before running the example, you must meet the following criteria:<ol><li> please first in your profile (if the ASP.net program is web.config, if it is the win form program, Then the app.config file, plus the following sentence:
<appSettings><br/>
<add key= "DSN" value= "server= (local) \netsdk;database=northwind; Trusted_connection=yes "/><br/>
</appSettings\><br/>
Note that this sentence must be added to the root node of the configuration file, that is, under <configuration> </li>
<li> you have installed the Microsoft MSDE database, if you do not install, you can find in your vs.net installation directory, such as I installed in e-disk, then MSDE installer for E:\Program Files\Microsoft Visual Studio. Net\frameworksdk\samples\setup\msde\instmsde.exe, in addition, make sure that your MSDE is started and can be started using NET start mssql$netsdk on the command line </li>
<li> The following example is just an example of a desktop database for MS SQL Server, and you can use a different database to do the experiment if you have a condition, and if you have any questions, you can contact me </li>
</ol>
<b> Example one: Perform a query operation to DataReader returns the result set </b><br/>
<code>
Note that the "DSN" here is the key name you gave in the configuration file, not the value;<br/>
Try<br/>
{<br/>
Command command=new command ();<br/>
Command. Connectionstring= "server= (local) \netsdk;database=northwind; Trusted_connection=yes ";<br/>
command.commandtext= "SELECT * from Orders where orderid= @orderid"; <br/(orderid= @orderid "; <br/) >
The following orders correspond to the field names in the SQL statement, and if the query statement is a stored procedure, insert the appropriate join parameter;<br/>
Command. parameters["OrderID"]=10249;<br/>
System.Data.IDataReader Dr=command. Executedatareader ();<br/>
}<br/>
catch (joybasedbexception e) <br/>
{<br/>
According to the example below you can make your own exception capture;<br/>
Console.WriteLine ("Error message is:" +e.message);<br/>
Console.WriteLine ("Error possible cause:" +e.reason);<br/>
}<br/>
///
if (Dr.read ()) <br/>
{<br/>
Read the data, according to your original DataReader action method can be;<br/>
...<br/>
}<br/>
Else<br/>
{<br/>
Perform your exception operation;<br/>
...<br/>
<br/>
}<br/>
Dr. Close ();<br/>
</code>
<b> Example two: Perform a query operation and return the DataSet object:</b><br/>
<code>
Command command=new command ();<br/>
Command. Connectionsetname= "DSN";<br/>
command.commandtext= "SELECT * FROM Orders";<br/>
Here we return a few dataset objects <br/>
The first is a dataset<br/> with a default table named DataSet as "table"
System.Data.DataSet Ds1=command. ExecuteDataset ();<br/>
Then return a custom Table object named "tablename" <br/>
System.Data.DataSet Ds2=command. ExecuteDataset ("tablename");<br/>
To return a dataset, we will limit the return of the result set, assuming that from the 12th record, query 50 records <br/>
System.Data.DataSet Ds3=command. ExecuteDataset ("tablename", 12,50);<br/>
At the same time, if you like, you can return only one datatable<br/>
System.Data.DataTable Table=command. Execute.datatable ();<br/>
Now you can perform a data-binding operation, DefaultView it directly <br/>
...<br/>
</code>
<b> example Three: Execute a paging query and return the DataSet object and the DataReader object </b><br/>
<code>
Command command=new command ();<br/>
Command. Connectionsetname= "DSN";<br/>
command.commandtext= "SELECT * FROM Orders";<br/>
Command. Pagesize=30;<br/>
Here you can use variable substitution, that is, to achieve dynamic paging effect <br/>
int currentpage=1;<br/>
System.Data.DataSet Ds=command. ExecuteDataset ("orderstable", CurrentPage);<br/>
Performs a binding operation so that DataList and other data-bound controls support paging (you also have to do something, such as the current number of pages is not greater than the total number of pages and not less than 0 equal to the judgment) <br/>
...<br/>
Below output datareader<br/>
System.Data.IDataReader Dr=command. Executedatareader (currentpage);<br/>
int i=0;<br/>
while (Dr.read ()) <br/>
{<br/>
Perform the actions you need <br/>
....<br/>
///
}<br/>
String showtext= "shared record" +command. recordset+ "article, a total of" +command. pagecount+ page, currently displays the first "+currentpage+" page;<br/>
<br/>
</code>
</example>

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.