學(xué)生管理系統(tǒng)實(shí)驗(yàn)報(bào)告.docx_第1頁
學(xué)生管理系統(tǒng)實(shí)驗(yàn)報(bào)告.docx_第2頁
學(xué)生管理系統(tǒng)實(shí)驗(yàn)報(bào)告.docx_第3頁
學(xué)生管理系統(tǒng)實(shí)驗(yàn)報(bào)告.docx_第4頁
學(xué)生管理系統(tǒng)實(shí)驗(yàn)報(bào)告.docx_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

ADO.NET實(shí)現(xiàn)數(shù)據(jù)庫基本操作一、實(shí)驗(yàn)?zāi)康?.掌握ADO.net數(shù)據(jù)庫連接方式。2.掌握ADO.net數(shù)據(jù)庫的增、刪、改、查的基操作。3 掌握ADO.net檢索和存儲Blob等大的二進(jìn)制數(shù)據(jù)。二、實(shí)驗(yàn)內(nèi)容建立一個簡單的學(xué)生信息管理程序,能夠增加、刪除、修改,查找學(xué)生的基本信息,在其中加入照片信息管理。三 程序界面 登錄界面:主界面:增加用戶界面:四:實(shí)驗(yàn)部分代碼 登錄代碼: 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 學(xué)生信?息 where 學(xué)號?=UserId; string sex=男D; if (rbnnan.Checked) sex=男D; else sex=女?; birthTime= BirthTimes(); string sql = insert into 學(xué)生信?息 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(新?學(xué)生信?息插?入?成功|。); else MessageBox.Show(該?學(xué)生號?已?被?占?用?,?信?息插?入?失敗。); 修改學(xué)生信息的代碼: private void btnUpdate_Click(object sender, EventArgs e) string constr = ConfigurationManager.ConnectionStringssql.ConnectionString; string sql1 = select count(*) from 學(xué)生信?息 where 學(xué)號?=UserId1; string sex = 男D; if (rbnnan.Checked) sex = 男D; else sex = 女?; birthTime = 2000-10-10; birthTime = BirthTimes(); string sql = update 學(xué)生信?息 set 姓?名?=UserName,性?別e=UserGender,出?生日?期=UserBirthdate,民?族?=UserNational,所屬?班級?=UserClass,家庭住?址=UserAddress where 學(xué)號?=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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論