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