




已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
ADO.NET實現數據庫基本操作一、實驗目的1.掌握ADO.net數據庫連接方式。2.掌握ADO.net數據庫的增、刪、改、查的基操作。3 掌握ADO.net檢索和存儲Blob等大的二進制數據。二、實驗內容建立一個簡單的學生信息管理程序,能夠增加、刪除、修改,查找學生的基本信息,在其中加入照片信息管理。三 程序界面 登錄界面:主界面:增加用戶界面:四:實驗部分代碼 登錄代碼: private void btnLogin_Click(object sender, EventArgs e) string constr = ConfigurationManager.ConnectionStringssql.ConnectionString; string sql = select count(*) from Login where UserName=UserName and UserPassword=UserPassword; SqlParameter pms = new SqlParameter new SqlParameter(UserName, txtUserName.Text.Trim(), new SqlParameter(UserPassword,txtUserPassword.Text) ; int obj= Convert.ToInt32( SqlHelper.ExecuteScalar(sql,pms); if (obj=1) stuInfo stu = new stuInfo(); stu.ShowDialog(); else MessageBox.Show(登?錄?失敗。,警告?, MessageBoxButtons.OK, MessageBoxIcon.Warning); 執(zhí)行sql語句的類代碼: public static class SqlHelper private static readonly string constr = ConfigurationManager.ConnectionStringssql.ConnectionString; public static int ExecuteNonquery(string sql, params SqlParameter pms) using (SqlConnection sqlcon = new SqlConnection(constr) using (SqlCommand sqlcmd = new SqlCommand(sql, sqlcon) sqlcon.Open(); if (pms != null) sqlcmd.Parameters.AddRange(pms); return sqlcmd.ExecuteNonQuery(); public static Object ExecuteScalar(string sql, params SqlParameter pms) using (SqlConnection sqlcon = new SqlConnection(constr) using (SqlCommand sqlcmd = new SqlCommand(sql, sqlcon) sqlcon.Open(); if (pms != null) sqlcmd.Parameters.AddRange(pms); return sqlcmd.ExecuteScalar(); public static SqlDataReader ExecuteReader(string sql, params SqlParameter pms) SqlConnection sqlcon = new SqlConnection(constr); using (SqlCommand sqlcmd = new SqlCommand(sql, sqlcon) sqlcon.Open(); if (pms != null) sqlcmd.Parameters.AddRange(pms); return sqlcmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); public static DataTable ExecuteSqlDataTable(string sql, params SqlParameter pms) using (SqlConnection sqlcon = new SqlConnection(constr) SqlDataAdapter adapter = new SqlDataAdapter(sql, sqlcon); if (pms != null) adapter.SelectCommand.Parameters.AddRange(pms); DataTable table = new DataTable(); adapter.Fill(table); return table; 增加用戶的代碼: private void btnInsert_Click(object sender, EventArgs e) string constr = ConfigurationManager.ConnectionStringssql.ConnectionString; string sql1 = select count(*) from 學生信?息 where 學號?=UserId; string sex=男D; if (rbnnan.Checked) sex=男D; else sex=女?; birthTime= BirthTimes(); string sql = insert into 學生信?息 values (userId,UserName,UserGender,UserBirthdate,UserNational,UserClass,UserAddress); SqlParameter pms = new SqlParameter new SqlParameter(userId, txtId.Text.Trim(), new SqlParameter(UserName,txtName.Text.Trim(), new SqlParameter(UserGender,sex), new SqlParameter(UserBirthdate, birthTime), new SqlParameter(UserNational,txtNational.Text.Trim(), new SqlParameter(UserClass,txtClass.Text.Trim(),new SqlParameter(UserAddress,txtAddress.Text.Trim(); SqlParameter pms1 = new SqlParameter new SqlParameter(userId, txtId.Text.Trim() ; int n = Convert.ToInt32(SqlHelper.ExecuteScalar(sql1, pms1); if (n != 1) SqlHelper.ExecuteNonquery(sql, pms); MessageBox.Show(新?學生信?息插?入?成功|。); else MessageBox.Show(該?學生號?已?被?占?用?,?信?息插?入?失敗。); 修改學生信息的代碼: private void btnUpdate_Click(object sender, EventArgs e) string constr = ConfigurationManager.ConnectionStringssql.ConnectionString; string sql1 = select count(*) from 學生信?息 where 學號?=UserId1; string sex = 男D; if (rbnnan.Checked) sex = 男D; else sex = 女?; birthTime = 2000-10-10; birthTime = BirthTimes(); string sql = update 學生信?息 set 姓?名?=UserName,性?別e=UserGender,出?生日?期=UserBirthdate,民?族?=UserNational,所屬?班級?=UserClass,家庭住?址=UserAddress where 學號?=userId; SqlParameter pms = new SqlParameter new SqlParameter(userId, txtId.Text.Trim(), new SqlParameter(UserName,txtName.Text.Trim(), new SqlParameter(UserGender, sex ), new SqlParameter(UserBirthdate, birthTime), new SqlParameter(UserNational,txtNational.Text.Trim(), new SqlParameter(UserClass,txtClass.Text.Trim(),new SqlParameter(UserAddress,txtAddress.Text.Trim(); SqlParameter pms1 = new SqlParameter new SqlParameter(userId1, txtId.Text.Trim() ; int n = Convert.ToInt32(SqlHelper.ExecuteScalar(sql1,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030年中國禮品套筆數據監(jiān)測研究報告
- 河北集裝箱冷庫施工方案
- 2025至2030年中國標本采集箱數據監(jiān)測研究報告
- 2025至2030年中國塑料彩印制袋數據監(jiān)測研究報告
- 2025至2030年中國可編程鍵盤數據監(jiān)測研究報告
- 2025至2030年中國低壓盤數據監(jiān)測研究報告
- 比較好的聯考數學試卷
- 2025年中國超高溫插入式流量計市場調查研究報告
- 2025年中國耐腐蝕旋渦泵市場調查研究報告
- 第六單元課題1 燃料的燃燒 第2課時 易燃物和易爆物的安全知識 化學反應中的能量變化教學設計-2024-2025學年九年級化學人教版上冊
- 學校小賣部承包合同范文
- 普外腹腔鏡手術護理常規(guī)
- 2025年湖南鐵道職業(yè)技術學院高職單招職業(yè)技能測試近5年常考版參考題庫含答案解析
- DB 63- T993-2011 三江源生態(tài)監(jiān)測技術規(guī)范
- 2024年全國職業(yè)院校技能大賽(礦井災害應急救援賽項)考試題庫(含答案)
- 《預制高強混凝土風電塔筒生產技術規(guī)程》文本附編制說明
- 北京市東城區(qū)2025年公開招考539名社區(qū)工作者高頻重點提升(共500題)附帶答案詳解
- 2025至2030年中國電子護眼臺燈數據監(jiān)測研究報告
- 2025年浙江省溫州樂清市融媒體中心招聘4人歷年高頻重點提升(共500題)附帶答案詳解
- 《獸醫(yī)基礎》練習題及參考答案
- 2025年煤礦探放水證考試題庫
評論
0/150
提交評論