Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # link SQLServer to insert and query data source code

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Data query: private void FullTab () {SqlConnection con1 = new SqlConnection (); / / create database link try {String con = "server=.;database=common_wjdl;uid=sa;pwd=db2008mima"; / / define database connection information con1.ConnectionString = con; con1.Open () / / Open the database String sql = "select * from Fileuploaded"; / / create a statement to query all data SqlDataAdapter ada1 = new SqlDataAdapter (sql, con); / / SqlDataAdapter objects. Used to populate the DataSet (dataset). DataSet myset = new DataSet (); SqlCommand cmd = con1.CreateCommand (); / / create database command cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader (); / / read the data stream from the database and store it in reader} catch (SqlException ee1) {Console.WriteLine (ee1.Message) / / print exception message} catch (IndexOutOfRangeException ee2) {Console.WriteLine (ee2.Message); / / print exception message}} data insertion: (about the same, just modify the SQL statement) String con = "server=.;database=common_wjdl;uid=sa;pwd=db2008mima" / / define database connection information con1.ConnectionString = con; con1.Open (); / / Open database String sql = "insert into Fileuploaded (FileID,FileName,FilePath,QRCodePath,FileSuffix) Values ('" + fileNameSave+ "','" + fileName+ "','" + filePath+ "','" + filePath+ "','" + fileSuffix+ "')" / / create statement to insert data into the database SqlCommand cmd = con1.CreateCommand (); / / create database command cmd.CommandText = sql; cmd.ExecuteNonQuery ()

Attachment: http://down.51cto.com/data/2366720

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report