C#_JDBC Connection Database

Source: Internet
Author: User

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Data.SqlClient;7 usingSystem.Data;8 9 namespaceMyschool.dalTen { One      Public classDBHelper A     { -         //Private CONST String conn = "Data source=.;i Nitial Catalog=myschool; User Id=gaofei; password=111111 "; -         Private Const stringconn ="Data Source=.;i Nitial Catalog=myschool; User Id=sa; Password=sa"; the         Private StaticSqlConnection connection =NewSqlConnection (conn); -  -  -         /// <summary> +         ///reading Data -         /// </summary> +         /// <returns></returns> A          Public StaticSqlDataReader Reader (stringsql) at         { -             Try -             { - connection. Open (); -SqlCommand Comm =NewSqlCommand (SQL, connection); -                 returnComm. ExecuteReader (commandbehavior.closeconnection); in             } -             Catch(Exception ex) to             { +                 Throw; -             } the         } *  $         /// <summary>Panax Notoginseng         ///Delete and change data -         /// </summary> the         /// <param name= "SQL" ></param> +         /// <returns></returns> A          Public Static intExecuteNonQuery (stringsql) the         { +             Try -             { $Connection. Open ();//Open a database connection $SqlCommand Comm =NewSqlCommand (SQL, connection); -                 returnComm. ExecuteNonQuery (); -             } the             Catch(Exception ex) -             {Wuyi                 Throw; the             } -             finally Wu             { - connection. Close (); About             } $         } -         /// <summary> -         ///returns a single value -         /// </summary> A         /// <param name= "SQL" ></param> +         /// <returns></returns> the          Public Static ObjectExecuteScalar (stringsql) -         { $             Try the             { theConnection. Open ();//Open a database connection theSqlCommand Comm =NewSqlCommand (SQL, connection); the                 returnComm. ExecuteScalar (); -  in             } the             Catch(Exception) the             { About                 Throw; the             } the             finally the             { + connection. Close (); -             } the         }Bayi         /// <summary> the         ///Return Data Set the         /// </summary> -         /// <param name= "SQL" ></param> -         /// <param name= "TableName" ></param> the         /// <returns></returns> the          Public StaticDataSet Fill (stringSqlstringtableName) the         { the             Try -             { theConnection. Open ();//Open Connection the                 //To create a data adapter object theSqlDataAdapter SDA =NewSqlDataAdapter (SQL, connection);94                 //Create a data set theDataSet ds =NewDataSet (); theSda. Fill (ds, TableName);//Populating data sets the                 returnds;98             } About             Catch(Exception ex) -             {101                 Throw;102                 //throws an exception that appears103                 //throw new Exception (e.message);104             } the             finally106             {107 connection. Close ();108             }109         } the     }111}

C#_JDBC Connection Database

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.