數(shù)據(jù)的查詢: private void FullTab() { SqlConnection con1 = new SqlConnection();//創(chuàng)建數(shù)據(jù)庫庫鏈接 try { String con = "server=.;database=common_wjdl;uid=sa;pwd=db2008mima";//定義數(shù)據(jù)庫連接信息 con1.ConnectionString = con; con1.Open();//打開數(shù)據(jù)庫 String sql = "select * from Fileuploaded";//創(chuàng)建語句查詢所有數(shù)據(jù) SqlDataAdapter ada1 = new SqlDataAdapter(sql, con);//SqlDataAdapter 對象。 用于填充DataSet (數(shù)據(jù)集)。 DataSet myset = new DataSet(); SqlCommand cmd = con1.CreateCommand();//創(chuàng)建數(shù)據(jù)庫命令 cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); //從數(shù)據(jù)庫中讀取數(shù)據(jù)流存入reader中 } catch (SqlException ee1) { Console.WriteLine(ee1.Message);//打印異常信息 } catch (IndexOutOfRangeException ee2) { Console.WriteLine(ee2.Message);//打印異常信息 } } 數(shù)據(jù)的插入:(大致都一樣,只需修改SQL語句就行) String con = "server=.;database=common_wjdl;uid=sa;pwd=db2008mima";//定義數(shù)據(jù)庫連接信息 con1.ConnectionString = con; con1.Open();//打開數(shù)據(jù)庫 String sql = "insert into Fileuploaded (FileID,FileName,FilePath,QRCodePath,FileSuffix) Values('"+fileNameSave+"','"+fileName+"','"+filePath+"','"+filePath+"','"+fileSuffix+"')";//創(chuàng)建語句向數(shù)據(jù)庫插入數(shù)據(jù) SqlCommand cmd = con1.CreateCommand();//創(chuàng)建數(shù)據(jù)庫命令 cmd.CommandText = sql; cmd.ExecuteNonQuery();
成都創(chuàng)新互聯(lián)公司是專業(yè)的麻章網(wǎng)站建設公司,麻章接單;提供網(wǎng)站設計、成都網(wǎng)站設計,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行麻章網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
分享標題:C#鏈接SQLServer實現(xiàn)插入和查詢數(shù)據(jù)源代碼
瀏覽地址:http://jinyejixie.com/article24/ipejce.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航、微信小程序、手機網(wǎng)站建設、網(wǎng)站制作、Google、營銷型網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)