Rapid development of vs.net+c# programs (-)

Source: Internet
Author: User
Tags count table name
Program
An existing database (SQL) table that quickly generates a tool for the corresponding stored procedure. SQLPilot.exe

SQLPilot.exe This program is written by a friend of CCF, please refer to http://bbs.et8.net/bbs/showthread.php?t=534183

Second, the existing database table, quickly generate lists, basic queries, advanced queries, insert new rows, delete, edit asp.net page tools asp.net Maker

http://www.hkvstore.com/aspnetmaker/

1. Database Operation class

The following is the C # code:

Header file:

Using system;using system.web.ui;using system.globalization;using system.data;using system.data.sqlclient;namespace Ns_db{public class c_db:usercontrol{

Returns the database connection string//********************************

public string Ewconnstr () {return "password=******; Persist Security info=true; User id=sa;initial catalog=******;D ata source=

(local) "; }//End EWCONNSTR

Returns a DataView based on Connection String & SQL//************ ******************************************

Public DataView Ewdataview (string sconn, string sSQL) {try {

Create a new Connection Object sqlconnection oconn = new SqlConnection (sconn);

Create a new DataAdapter using the Connection Object and SQL statement SqlDataAdapter oDa = new SqlDataAdapter (sSQL, oconn);

Create a new dataset Object to fill with Data DataSet oDs = new DataSet ();

Fill the DataSet with Data from the DataAdapter Object Oda.fill (oDs, "Ewdataset"); Return ods.tables[0].  DefaultView;   catch (SqlException oerr) {session["dberrmsg"] = Ewdataerrormessage (Oerr);  return null; }//End Ewdataview

Returns a DataView for linking//*********************************

Public DataView Ewdataviewlink (string sconn, string stable/* table name */, String slnkfld, String sdispfld, string sDispFld2, str ing sfilterfld, string sorderby/*/Series/, String sordertype/* collation */, BOOL bdistinct/* excluding duplicate values/, string sfilter) {string  sSQL; try {

Construct SQL Statement sSQL = "select";   if (bdistinct) {sSQL = = "DISTINCT";   sSQL + = "[" + Slnkfld + "], [" + SDISPFLD +] ";   if (sDispFld2!= "") {sSQL = ", [" + SDispFld2 +] ";   } if (Sfilterfld!= "") {sSQL + = ", [+ SFILTERFLD +]";   } sSQL + = "from [" + Stable + "]";   if (sfilter!= "") {sSQL + = "WHERE" + sfilter;   } if (Sorderby!= "") {sSQL + = "ORDER BY [" + Sorderby + "]" + sordertype; }

Create a new Connection Object using the Connection String sqlconnection oconn = new SqlConnection (sconn);

Create a new DataAdapter using the Connection Object and SQL statement SqlDataAdapter oDa = new SqlDataAdapter (sSQL, oconn);

Create a new dataset Object to fill with Data DataSet oDs = new DataSet ();

Fill the DataSet with Data from the DataAdapter Object Oda.fill (oDs, "Ewdataset");

Create the TextField and Valuefield Columns ods.tables[0].   Columns.Add ("Ewvaluefield", Type.GetType ("System.String"), "[" + Slnkfld + "]"); if (sDispFld2 = = "") {Ods.tables[0].   Columns.Add ("Ewtextfield", Type.GetType ("System.String"), "[" + Sdispfld + "]"); } else {Ods.tables[0]. Columns.Add ("Ewtextfield", Type.GetType ("System.String"), "[+ SDISPFLD +"] +

', ' + ["+ SDispFld2 +]"); Return ods.tables[0].  DefaultView;   catch (SqlException oerr) {session["dberrmsg"] = Ewdataerrormessage (Oerr);  return null; }//End Ewdataviewlink

Returns the number of Records based on Connection String & SQL//********* ************************************************

public int Ewrecordcount (string sconn, string stable, string swhere) {string sSQL; try {

Construct SQL sSQL = "Select COUNT (*) from [" + Stable + "]";   if (Swhere!= "") {sSQL + = "WHERE" + swhere; }

Create a new Connection Object using the Connection String sqlconnection oconn = new SqlConnection (sconn);

Create a new DataAdapter using the Connection Object and SQL statement SqlDataAdapter oDa = new SqlDataAdapter (sSQL, oconn);

Create a new DataSet object to fill with Data DataSet oDs = new DataSet ();

Fill the DataSet with Data from the DataAdapter Object Oda.fill (oDs, "Ewdataset"); Return Convert.ToInt32 (Ods.tables[0].  Rows[0][0]);   catch (SqlException oerr) {session["dberrmsg"] = Ewdataerrormessage (Oerr);  return 0; }//End Ewrecordcount

Returns 1-page DataView according to Connection String & SQL//*** ********************************************************

Public DataView ewdataviewpage (string sconn, string ssql, int icurrentrec, int ipagesize) {try {

Create a new Connection Object using the Connection String sqlconnection oconn = new SqlConnection (sconn);

Create a new DataAdapter using the Connection Object and SQL statement SqlDataAdapter oDa = new SqlDataAdapter (sSQL, oconn);

Create a new DataSet object to fill with Data DataSet oDs = new DataSet ();

Fill the DataSet with Data from the DataAdapter Object Oda.fill (oDs, Icurrentrec, Ipagesize, "Ewdataset"); Return ods.tables[0].  DefaultView;   catch (SqlException oerr) {session["dberrmsg"] = Ewdataerrormessage (Oerr);  return null; }//End Ewdataviewpage

Return a DataReader based on Connection & SQL//************* ************************************

Public SqlDataReader Ewdatareader (SqlConnection oconn, string sSQL) {try {

Create a DataReader Object SqlDataReader oDr;

Create a new Command Object using the Connection and SQL statement SqlCommand ocmd = new SqlCommand (sSQL, oconn);

Execute the SQL statement against the Command to get the DataReader oDr = Ocmd.executereader ();  return oDr;   catch (SqlException oerr) {session["dberrmsg"] = Ewdataerrormessage (Oerr);  return null; }//End Ewdatareader

Return error message based on Error Object//********************** ************************

public string Ewdataerrormessage (SqlException oerr) {string sdberrmsg;  Sdberrmsg = ""; for (int i = 0; I <= oerr.errors.count-1 i++) {sdberrmsg = = ' message: + oerr.errors[i]. Message + "+" line number: "+ oerr.errors[i]." LineNumber + "" + "Source:" + oerr.errors[i]. Source + "" + "Procedure:" + oerr.errors[i].  Procedure + ""; return sdberrmsg; }//End Ewdataerrormessage

return Upload File Name//***************************

public string Ewuploadfilename (string sfilename) {string soutfilename;

Amend your logic here soutfilename = sFileName;

Return computed output file name return soutfilename; }//End Ewuploadfilename

Return formatted number similar to VB formatnumber//-incl Udeleadingdigit is not supported//******************************************************

public string Ewformatnumber (object oNo, int idecplace, int iuseparen, int igroupdigits) {NumberFormatInfo Onfi = (numbe  Rformatinfo) NumberFormatInfo.CurrentInfo.Clone (); Onfi.numberdecimaldigits = Idecplace; Numdigitsafterdecimal

Includeleadingdigit:not used if (Iuseparen = = 1)//useparensfornegativenumbers:true {Onfi.numbernegativepatter  n = 0;  else if (Iuseparen = 0)//useparensfornegativenumbers:false {onfi.numbernegativepattern = 1;  } if (igroupdigits = = 1)//groupdigits:true {onfi.numbergroupseparator = ",";  else if (igroupdigits = 0)//groupdigits:false {onfi.numbergroupseparator = ""; }

  //Cast for different data types  if (ONo are short)//short  {return ((short) oNo). ToString ("n", ONFI); }  else if (ONo is ushort)//ushort  {return ((ushort) oNo). ToString ("n", ONFI); }  else if (oNo is int)//int  {return ((int) oNo). ToString ("n", ONFI); }  else if (ONo is uint)//uint  {return ((UINT) oNo). ToString ("n", ONFI); }  else if (ONo is long)//long  {return ((Long) oNo). ToString ("n", ONFI); }  else if (ONo is ulong)//ulong  {return ((ULONG) oNo). ToString ("n", ONFI); }  else if (ONo is float)//float  {return ((float) oNo). ToString ("n", ONFI); }  else if (ONo is double)//double  {return (double) oNo). ToString ("n", ONFI); }  else if (ONo is decimal)//decimal  {return ((decimal) oNo). ToString ("n", ONFI); }  else  {return ((decimal) oNo). ToString ("n", Onfi); } }

Return formatted Currency similar to VB formatcurrency -IncludeLeadingDigit is not supported//**********************************************************

public string Ewformatcurrency (object oNo, int idecplace, int iuseparen, int igroupdigits) {NumberFormatInfo Onfi = (Num  Berformatinfo) NumberFormatInfo.CurrentInfo.Clone (); Onfi.currencydecimaldigits = Idecplace; Numdigitsafterdecimal

Includeleadingdigit:not used if (Iuseparen = = 1)//useparensfornegativenumbers:true {Onfi.currencynegativepatt  Ern = 0;  else if (Iuseparen = 0)//useparensfornegativenumbers:false {onfi.currencynegativepattern = 1;  } if (igroupdigits = = 1)//groupdigits:true {onfi.currencygroupseparator = ",";  else if (igroupdigits = 0)//groupdigits:false {onfi.currencygroupseparator = ""; }

  //Cast for different data types  if (ONo are short)//short  {return ((short) oNo). ToString ("C", ONFI); }  else if (ONo is ushort)//ushort  {return ((ushort) oNo). ToString ("C", ONFI); }  else if (oNo is int)//int  {return ((int) oNo). ToString ("C", ONFI); }  else if (ONo is uint)//uint  {return ((UINT) oNo). ToString ("C", ONFI); }  else if (ONo is long)//long  {return ((Long) oNo). ToString ("C", ONFI); }  else if (ONo is ulong)//ulong  {return ((ULONG) oNo). ToString ("C", ONFI); }  else if (ONo is float)//float  {return ((float) oNo). ToString ("C", ONFI); }  else if (ONo is double)//double  {return (double) oNo). ToString ("C", ONFI); }  else if (ONo is decimal)//decimal  {return ((decimal) oNo). ToString ("C", ONFI); }  else  {return ((decimal) oNo). ToString ("C", Onfi); } }

Return formatted Percent similar to VB formatpercent//- IncludeLeadingDigit is not supported//********************************************************

public string Ewformatpercent (object oNo, int idecplace, int iuseparen, int igroupdigits) {NumberFormatInfo Onfi = (Numb  Erformatinfo) NumberFormatInfo.CurrentInfo.Clone (); Onfi.currencydecimaldigits = Idecplace; Numdigitsafterdecimal

Includeleadingdigit:not used if (Iuseparen = = 1)//useparensfornegativenumbers:true {Onfi.currencynegativepatt  Ern = 0;  else if (Iuseparen = 0)//useparensfornegativenumbers:false {onfi.currencynegativepattern = 1;  } if (igroupdigits = = 1)//groupdigits:true {onfi.currencygroupseparator = ",";  else if (igroupdigits = 0)//groupdigits:false {onfi.currencygroupseparator = ""; }

  //Cast for different data types  if (ONo are short)//short  {return ((short) oNo). ToString ("P", ONFI); }  else if (ONo is ushort)//ushort  {return ((ushort) oNo). ToString ("P", ONFI); }  else if (oNo is int)//int  {return ((int) oNo). ToString ("P", ONFI); }  else if (ONo is uint)//uint  {return ((UINT) oNo). ToString ("P", ONFI); }  else if (ONo is long)//long  {return ((Long) oNo). ToString ("P", ONFI); }  else if (ONo is ulong)//ulong  {return ((ULONG) oNo). ToString ("P", ONFI); }  else if (ONo is float)//float  {return ((float) oNo). ToString ("P", ONFI); }  else if (ONo is double)//double  {return (double) oNo). ToString ("P", ONFI); }  else if (ONo is decimal)//decimal  {return ((decimal) oNo). ToString ("P", ONFI); }  else  {return ((decimal) oNo). ToString ("P", onfi); }&NBSP}}//End Class}//End NameSpace


Related Article

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.