This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24442|Reply: 1

[Source] c# connection to sqlserver database DBHelp code

[Copy link]
Posted on 10/9/2014 2:14:17 PM | | |
It will be used for some projectsdatabase, below is the code for C# to connect to the local database.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.SqlClient;
  6. using System.Data;

  7. namespace Chairman
  8. {
  9.     class DBHelp
  10.     {
  11.         private const string strConn = "server=.;database=QQ;integrated security=true;";
  12.         public static void update(string sql)
  13.         {
  14.             string strSql = sql;
  15.             SqlConnection sqlConn = new SqlConnection(strConn);
  16.             SqlCommand sqlComm = new SqlCommand(strSql, sqlConn);
  17.             sqlConn.Open();
  18.             sqlComm.ExecuteNonQuery();
  19.             sqlConn.Close();
  20.         }

  21.         public static DataTable select(string sql)
  22.         {
  23.             DataTable dt = new DataTable();

  24.             SqlDataAdapter sqlDA = new SqlDataAdapter(sql, strConn);

  25.             sqlDA.Fill(dt);

  26.             return dt;
  27.         }
  28.     }
  29. }
Copy code






Previous:EPUBReader reader, a must-have for opening EPUB files
Next:Which is the strongest mining technology? Dongguan, China looking for your mother, all kinds of gods reply!
Posted on 3/29/2015 11:45:56 AM |
The teacher said that the phone call is very vivid
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com