C#常用增刪改查源碼精_第1頁
C#常用增刪改查源碼精_第2頁
C#常用增刪改查源碼精_第3頁
C#常用增刪改查源碼精_第4頁
C#常用增刪改查源碼精_第5頁
免費預覽已結束,剩余1頁可下載查看

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、這個是添加的代碼 using System; using System.Collections.Generic; usingSystem.Co mponen tModel; using System.Data; using System.Drawi ng; usingSystem.Text; using System.Wi ndows.Forms; using System.Data.SqlClie nt; n ames pace 學生成績管理系統(tǒng) public partial class studentluru : Form / CurrencyManager cmAme nd; / Sql

2、C onn ecti on sqlC onn ecti on1 = new SqlC onnection(; p ublic stude ntluru( In itializeCo mponen t(; p rivate void stude ntluru_Load(object sen der, Eve ntArgs e / 錄入 p rivate void butt on 5_Click(object sen der, Eve ntArgs e stri ng sno = textBox1.Text; stri ng sn ame = textBox2.Text; stri ng ssex

3、 = textBox3.Text; stri ng sage = textBox4.Text; stri ng sclass = textBox5.Text; stri ng sde pt = textBox6.Text; stri ng saddress = textBox7.Text; stri ng sphone = textBox8.Text; stri ng sqq = textBox9.Text; if (textBox1.Text = "" | textBox2.Text = "" | textBox5.Text = ""

4、; if (textBox1.Text="" MessageBox.Show("學號不能為空","警告提示",MessageBoxButt on s.OKCa ncel, MessageBoxIco n.Error; textBox1.Focus(; return; if(textBox2.Text = "" MessageBox.Show("姓名不能為空","警告提示",MessageBoxButt on s.OKCa ncel, MessageBoxIco n.Error

5、; textBox2.Focus(; return; if(textBox5.Text = "" MessageBox.Show("班級不能為空","警告提示",MessageBoxButt on s.OKCa ncel, MessageBoxIco n.Error; textBox5.Focus(; return; else stri ng conn str = "server=IT32;uid=sa; pwd='sa'database=sc;" try SqlC onn ectio n conn

6、 = new SqlC onn ectio n(c onn str; conn.Open(; stri ng sqli nsert = "in sert into stude ntinfo valuesC" + sno + "','" + sn ame + "','" + ssex + "','" + sage + "','" + sclass + "','" + sde pt + "&

7、#39;,'" + saddress + "','" + sphone + "','" + sqq + "”' SqlComma nd sc = newSqlComma nd(sqli nsert, conn; sc.ExecuteN on Query(; textBox1.Text = "" textBox2.Text =""textBox3.Text = "" textBox4.Text = "" tex

8、tBox5.Text = "" textBox6.Text =""textBox7.Text = "" textBox8.Text = "" textBox9.Text = "" MessageBox.Show("數(shù)據(jù)已 經(jīng)添加成功","溫馨提示"conn.Close(; catch (Exception ex MessageBox.Show(ex.ToStri ng(; p rivate void butt on 8_Click(object sen d

9、er, EventArgs e this.Dispose(; 這個是查詢界面的代碼 :using System; usingSystem.Collectio ns.Ge neric; using System.Co mponen tModel; using System.Data; usingSystem.Draw ing; using System.Text; using System.Wi ndows.Forms; usingSystem.Data.SqlClient; namespac學生成績管理系統(tǒng) public partial class stude ntchax un : Form

10、 DataTable dt = new DataTable(; stri ng per; stri ng sno;Curre ncyMa nager cmAme nd; p ublic stude ntchax un( In itializeCo mponen t(; p ublic stude ntchax un( stri ng k, stri ng s In itializeCo mponen t(; per = k; sno = s; p rivatevoid stude ntchaxun_Load(object sen der, Eve ntArgs e / TODO 這行代碼將數(shù)據(jù)

11、 加載到表“studentDataSet.studentinf中。您可以根據(jù)需要移動或移除它。/this.stude ntin foTableAda pter.Fill(this.stude ntDataSet.stude ntinfo; /數(shù)據(jù)綁定 if (per = "超級用戶" string sqlsel = "select * from studentinfo " DataTable dt = bangding(sqlsel;cmAme nd = (Curre ncyMa nagerBi ndi ngCo ntextdt; this.dataGr

12、idView1.DataSource = dt;boBox1.DataSource = dt; boBox1.Dis playMember = "sno"boBox2.DataSource = dt; boBox2.Dis playMember = "sn ame" if (per ="普通用戶" string sqlsel = "select * from studentinfo where sno=”' + sno + "'"DataTable dt = bangdin g(sqlse

13、l; cmAme nd = (Curre ncyMa nagerBi ndi ngCon textdt;this.dataGridView1.DataSource = dt; boBox1.DataSource = dt;boBox1.Dis playMember = "sno" boBox2.E nabled = false;this.radioButt on 2.E nabled = false; /this.toolStri pButt on 1.E nabled = false;/this.toolStri pButto n2.E nabled = false; /

14、this.toolStri pButt on 3.E nabled = false;/this.toolStri pButt on 4.E nabled = false; /boBox2.DataSource = dt;/boBox2.Dis playMember = "sn ame" DataTable ban gdi ng(stri ng sqlsel stri ng conn str = "server=.;uid=sa ;p wd=sa;database=sc" using (SqlCo nn ecti on conn = new SqlC on

15、nection(conn str conn.Open(; DataSet ds = new DataSet(; SqlDataAda pter da = new SqlDataAda pter(sqlsel, conn; da.Fill(ds, "coust" DataTable dt = ds.Tables"coust" conn. Close(; retu rn dt; p rivate void butt on 1_Click(object sen der,Eve ntArgs e if (this.radioButt on 1.Checked =

16、 true stri ng xuehao = comboBox1.Text;stri ng sqlsel = "select * from stude ntinfo where sno='" + xuehao + "'"this.dataGridViewl.DataSource = bangdin g(sqlsel; else stri ng xingming = comboBox2.Text; stri ng sqlsel = "select * from stude nti nfo where sn ame='&qu

17、ot; + xingming+ "”' this.dataGridViewl.DataSource = bangdin g(sqlsel; p rivate void radioButt on 1_CheckedCha nged(object sen der. Eve ntArgs e if (this.radioButt on.Checked = true boBox1.E nabled = true;boBox2.E nabled = false; else boBoxl.E nabled = false;boBox2.E nabled = true; p rivate

18、void checkstate(i nt pos if (pos = 0 toolStri pButt on 1.E nabled = false; toolStri pButt on 2.E nabled = false;toolStri pButt on 3.E nabled = true; toolStri pButt on 4.E nabled = true; else toolStri pButt on 1.E nabled = true; toolStri pButto n2.E nabled = true;toolStri pButto n3.E nabled = true; t

19、oolStri pButt on 4.E nabled = true; / 首記錄 private void toolStri pButt on 1_Click(object sen der, Eve ntArgs e cmAme nd.Po siti on = 0;/設置 為 0.回到首記錄 this.dataGridView1.Select(; checkstate(cmAmend.Position; /上一條 p rivate void toolStri pButt on 2_Click(object sen der,Eve ntArgs e cmAme nd.Po sitio n-;

20、this.dataGridView1.Select(;checkstate(cmAme nd. Po sitio n; /下一條 p rivate void toolStri pButt on 3_Click(object sen der, Eve ntArgs e cmAme nd.Po sitio n+; this.dataGridView1.Select(; checkstate(cmAme nd.Po sitio n; /末記錄 p rivate void toolStri pButt on 4_Click(object sen der, Eve ntArgs e cmAme nd.P

21、o siti on = cmAme nd.Co unt - 1;this.dataGridView1.Select(; checkstate(cmAmend.Position; 刪除的代碼:usingSystem; using System.Collectio ns.Ge neric; using System.Co mponen tModel; usingSystem.Data; using System.Drawi ng; using System.Text; using System.Wi ndows.Forms; using System.Data.SqlClient; namespa

22、c學生成績管理系統(tǒng) public partial class stude ntsha nchu : Form Curre ncyMa nager cmAme nd; p ublic stude ntsha nchu( In itializeCo mponen t(; p rivate void stude ntsha nchu_Load(objectsen der, Eve ntArgs e / TODO:這行代碼將數(shù)據(jù)加載到表 “ stude ntDataSet.stude ntinfo”中。您可以根據(jù)需要移動或移除它。/this.stude ntin foTableAda pter.Fil

23、l(this.stude ntDataSet.stude ntinfo; /數(shù) 據(jù)綁定 stri ng sqlsel = "select * from stude ntinfo " DataTable dt = bangdin g(sqlsel; cmAme nd = (Curre ncyMa nagerBi ndingCon textdt; this.dataGridViewl.DataSource = dt; this.textBoxl.DataBi ndi ngs.Add("text", dt, "s no" this.text

24、Box2.DataBi ndi ngs.Add("text", dt, "s name" this.textBox3.DataBi ndi ngs.Add("text", dt, "ssex"this.textBox4.DataB in di ngs.Add("text", dt, "sage"this.textBox5.DataBi ndi ngs.Add("text", dt, "sclass"this.textBox6.DataB

25、i ndin gs.Add("text", dt, "sde pt"this.textBox7.DataB in di ngs.Add("text", dt, "saddress"this.textBox8.DataB in di ngs.Add("text", dt, "s pho ne"this.textBox9.DataB indin gs.Add("text", dt, "sqq" DataTable ban gdi ng(st

26、n ng sqlsel stri ng conn str = "server=.;uid=sa ;p wd=sa;database=sc" using (SqlCo nn ecti on conn = new SqlC onnection(conn str conn.Open(; DataSet ds = new DataSet(; SqlDataAda pter da = new SqlDataAda pter(sqlsel, conn; da.Fill(ds, "coust" DataTable dt = ds.Tables"coust&q

27、uot; conn. Close(; retu rn dt; p rivate void checkBox1_CheckedCha nged(object sen der, Eve ntArgs e if (checkBox1.Checked = true this.Height = 450; else this.Height = 250; private void butt on 1_Click(object sender, EventArgs e if (MessageBox.Show(你確定要刪除該記錄嗎","詢問",MessageBoxButt on s.

28、OKCa ncel, MessageBoxIc on .Questi on = DialogResult.OK intpos = this.dataGridView1.Curre ntCelI.Rowl ndex; 獲取該行 stri ng conn str = "server=.;uid=sa; pwd=sa;database=sc" using (SqlC onn ectio n conn = newSqlCo nn ecti on(conn str conn.Open(; DataSet ds = new DataSet(; stri ng sqlset = &quo

29、t;select* from stude ntin fo" / 數(shù)據(jù)集 SqlDataAda pter da = new SqlDataAda pter(sqlset, conn;da.Fill(ds, "coust" DataTable dt = ds.Tables"coust"SqlComma ndBuilder cb = new SqlComma ndBuilder(da; dt.Rows pos.Delete(;da.U pdate(ds, "coust" textBox1.Text = "" t

30、extBox2.Text = "" textBox3.Text =""textBox4.Text = "" textBox5.Text = "" textBox6.Text = "" textBox7.Text =""textBox8.Text = "" textBox9.Text = "" this.dataGridView1.DataSource =bangding(sqlset; MessageBox.Show(恭喜你已成功刪除&

31、quot;,"溫馨提示"conn.Close(; 修改的代碼:using System; using System.Collections.Generic;using System.Co mponen tModel; using System.Data; using System.Draw ing; using System.Text; using System.Wi ndows.Forms; using System.Data.SqlClie nt; n ames pace 學生成績管理系統(tǒng) p ublic p artial class stude ntxiugai :

32、Form stri ng conn str = "server=.;uid=sa ;p wd=sa;database=sc" stri ng per; stri ng sno; Curre ncyMa nager cmAme nd; p ublic stude ntxiugai( In itializeCo mponen t(; p ublic stude ntxiugai(stri ng k,stri ng s In itializeCo mponen t(; per = k; sno = s; p rivate void checkBox1_CheckedCha nge

33、d(object sen der, Eve ntArgs e if (checkBox1.Checked = true /this.Height = 450; comboBox1.E nabled = false; textBox1.E nabled = false; else /this.Height = 250; comboBoxl.E nabled = true; textBoxl.E nabled = true; p rivate void studentxiugai_Load(object sender, EventArgs e /數(shù)據(jù)綁定 if (per ="超級用戶&q

34、uot; stri ng sqlsel = "select * from stude nti nfo order by sno asc " DataTable dt = bangdin g(sqlsel; cmAme nd = (Curre ncyMa nagerB indingCon textdt;boBoxl.DataSource = dt; boBox1.Dis playMember = "sno"this.textBoxl.DataBi ndi ngs.Add("text", dt, "s name"thi

35、s.textBox2.DataB in di ngs.Add("text", dt, "ssex"this.textBox3.DataB in di ngs.Add("text", dt, "sage"this.textBox4.DataB in di ngs.Add("text", dt, "sclass"this.textBox5.DataB in di ngs.Add("text", dt, "sde pt"this.textBo

36、x6.DataBi ndi ngs.Add("text", dt, "saddress"this.textBox7.DataB in di ngs.Add("text", dt, "s pho ne"this.textBox8.DataB in di ngs.Add("text", dt, "sqq" if (per ="普通用戶" stri ng sqlsel ="select *from stude nti nfo where sno=

37、9;" + sno + "'" DataTable dt = bangdin g(sqlsel;boBoxl.DataSource = dt; boBox1.Dis playMember = "sno"this.textBoxl.DataB in di ngs.Add("text", dt, "s name"this.textBox2.DataB in di ngs.Add("text", dt, "ssex"this.textBox3.DataB in d

38、i ngs.Add("text", dt, "sage"this.textBox4.DataB in di ngs.Add("text", dt, "sclass"this.textBox5.DataB in di ngs.Add("text", dt, "sde pt"this.textBox6.DataBi ndi ngs.Add("text", dt, "saddress"this.textBox7.DataB in di ngs

39、.Add("text", dt, "s pho ne"this.textBox8.DataBi ndi ngs.Add("text", dt, "sqq" DataTable ban gdi ng(stri ng sqlsel / stri ng conn str = "server=.;uid=sa ;p wd=sa;database=sc" using (SqlC onnection conn = new SqlC onnection(conn str conn.Open(; DataSet

40、 ds = new DataSet(; SqlDataAda pter da = new SqlDataAda pter(sqlsel, conn; da.Fill(ds, "coust" DataTable dt = ds.Tables"coust" conn. Close(; retu rn dt; p rivate void butt on 1_Click(object sen der, Eve ntArgs e if (checkBox1.Checked = true stri ng sno = comboBox1.Text;stri ng sn

41、 ame = textBox1.Text; stri ng sex = textBox2.Text; stri ng age = textBox3.Text;stri ng sclass = textBox4.Text; stri ng sde pt = textBox5.Text; stri ng saddress = textBox6.Text; stri ng sphone = textBox7.Text; stri ng sqq = textBox8.Text; if (textBox2.Text = "" | textBox3.Text = "" | textBox4.Text = "" | textBox5.Text ="" if (textBox2.Text = "" MessageBox.Show("性別不能為空"

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論