C # link SQL Server implementation inserts and queries data source code

Source: Internet
Author: User

Data query: Private void fulltab ()  {        sqlconnection  con1 = new sqlconnection ();//CREATE DATABASE library links              try            {                 string con  =  "server=.; Database=common_wjdl;uid=sa;pwd=db2008mima ";//define Database connection information                  con1. connectionstring = con;                 con1. Open ();//Opening Database                  string sql =  "select * from fileuploaded";//Create statement query all data             &nbsP;    sqldataadapter ada1 = new sqldataadapter (Sql, con);// The sqldataadapter  object.   for populating dataset  (Datasets).                 DataSet  Myset = new dataset ();                 sqlcommand cmd = con1. CreateCommand ();//CREATE DATABASE command                  cmd.CommandText = sql;                 sqldatareader reader = cmd. ExecuteReader ();  //read data stream from the database into reader              }            catch  (sqlexception  EE1)             {                 console.writeline (ee1. message);//print exception information             }             catch  (indexoutofrangeexception ee2)  {                  Console.WriteLine (Ee2. message);//print exception information             }         }         Data insertion: (roughly the same, just modify the SQL statement on the line)              String con =  "server=.; Database=common_wjdl;uid=sa;pwd=db2008mima ";//define Database connection information                           &Nbsp;  con1. connectionstring = con;                             con1. Open ();//Opening Database                              String sql =  "Insert  into Fileuploaded  (Fileid,filename,filepath,qrcodepath,filesuffix)  values (' "+filenamesave + "', '" "+filename+" ', ' "+filepath+" ', ' "+filepath+" ', ' "+filesuffix+" ');//CREATE statement insert data into database                               sqlcommand cmd = con1. CreateCommand ();//CREATE DATABASE command                        &Nbsp;     cmd. commandtext = sql;                             cmd. ExecuteNonQuery ();


This article is from the "Secrets of Technology-Liu Congcong creation" blog, make sure to keep this source http://liucongcong.blog.51cto.com/11527480/1931683

C # link SQL Server implementation inserts and queries data source code

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.