显示数据计算机工程学院计算机信息管理专业_第1页
显示数据计算机工程学院计算机信息管理专业_第2页
显示数据计算机工程学院计算机信息管理专业_第3页
显示数据计算机工程学院计算机信息管理专业_第4页
显示数据计算机工程学院计算机信息管理专业_第5页
免费预览已结束,剩余20页可下载查看

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、编写代码显示更新数据1界面设计3 个Label,3 个按钮 Button,3 个文本框 TextBox,一个列表框 ListBox1更改窗体的标题(Label)的 Text 属性更改23更改 TextBox 的 Name 属性更改文本框 TextBox1 的 ReadOnly 属性为 True4更改 TextBox 的 Name 属性更改 TextBox 的 Name 属性5更改按钮的 Name 属性更改按钮的 Text 属性6更改按钮的 Name 属性更改按钮的 Text 属性7更改按钮的 Name 属性更改按钮的 Text 属性8更改 ListBox 的 Name 属性92编写相关代码双击

2、窗体空白处10增加对相关名称空间的编写一个用于显示学生信息的方法11编写窗体的 Load 事件处理代码双击列表框12编写该列表框的 SelectedIndexChanged 事件的处理代码双击刷新按钮13编写该按钮单击事件的处理代码双击“更改(方法 1)”按钮14编写该按钮单击事件的处理代码双击“更改(方法 2)”按钮15编写该按钮单击事件的处理代码双击文本框16编写该文本框 TextChanged 事件的处理代码双击文本框17编写该文本框 TextChanged 事件的处理代码代码如下(粗体字才是需要输入的代码)18using System;using System.Collections.

3、Generic; usingponentM; using System.Data;using System.Drawing; using System.Text;using System.Windows.Forms; using System.Data.SqlCnt;namespace WindowsApplication2public partial class Form1 : Formpublic Form1()ponent();public void ShowStudentInfo()19this.lsbInfo.Items.Clear();stringStr = Data Source

4、=.SQL2005EXPRESS;InitialCatalog=StudentDB;egrated Security=True;SqlConnection myConnection = new SqlConnection(Str);/string Str = Data Source=.SQL2005EXPRESS;Initial Catalog=StudentDB;Persist Security Info=True;User ID=ssword=sa;/SqlConnection myConnection = new SqlConnection(Str); myConnection.Open

5、();mandmand = myComand(); mandText = SELECT * FROM student;SqlDataReader myReader =mand.ExecuteReader(); while (myReader.Read()this.lsbInfo.Items.Add(myReadername + ( + myReaderage+);myReader.Close(); myConnection.Close(); this.txbID.Text = ; this.txbName.Text = ; this.txbAge.Text = ;private void Fo

6、rm1_Load(objecder, EventArgs e)this.ShowStudentInfo();this.btnUpdate1.Enabled = false;this.btnUpdate2.Enabled = false;private void lsbInfo_SelectedIndexChanged(objecder, EventArgs e)string Str = Data Source=.SQL2005EXPRESS;Initial Catalog=StudentDB;egrated Security=True;SqlConnection myConnection =

7、new SqlConnection(Str);/string Str = Data Source=.SQL2005EXPRESS;Initial Catalog=StudentDB;Persist Security Info=True;User ID=ssword=sa;/SqlConnection myConnection = new SqlConnection(Str);myConnection.Open();SqlDataAdapter myAdapter = new SqlDataAdapter(SELECT * FROM student, myConnection);DataSet

8、myDataSet = new DataSet();myAdapter.Fill(myDataSet, myStudentTable);this.txbID.Text = myDataSet.TablesmyStudentTable.Rowsthis.lsbInfo.SelectedIndexid.ToString();this.txbName.Text = myDataSet.TablesmyStudentTable.Rowsthis.lsbInfo.SelectedIndexname.ToString();this.txbAge.Text =myDataSet.TablesmyStuden

9、tTable.Rowsthis.lsbInfo.SelectedIndexage.ToString();myConnection.Close();this.btnUpdate1.Enabled = false;this.btnUpdate2.Enabled = false;private void btnRefresh_Click(objecder, EventArgse)this.ShowStudentInfo();this.btnUpdate1.Enabled = false;this.btnUpdate2.Enabled = false;private void btnUpdate1_C

10、lick(objecder, EventArgse)Catalog=StudentDB;egrated Security=True;SqlConnection myConnection = new SqlConnection(Str);/string Str = Data Source=.SQL2005EXPRESS;Initial Catalog=StudentDB;Persist Security Info=True;User ID=ssword=sa;/SqlConnection myConnection = new SqlConnection(Str);myConnection.Ope

11、n();SqlDataAdapter myAdapter = new SqlDataAdapter(SELECT * FROM student, myConnection);mandBuilder myBuilder = dBuilder(myAdapter);DataSet myDataSet = new DataSet();myAdapter.Fill(myDataSet, myStudentTable);myDataSet.TablesmyStudentTable.Rowsthis.lsbInfo.SelectedIndexname = this.txbName.Text;myDataS

12、et.TablesmyStudentTable.Rowsthis.lsbInfo.SelectedIndexage = Convert.To32(this.txbAge.Text);private voidbtnUpdate2_Click(objecder, EventArgs e)string Str = Data Source=.SQL2005EXPRESS;Initial Catalog=StudentDB;egrated Security=True;SqlConnection myConnection = new SqlConnection(Str);/string Str = Dat

13、a Source=.SQL2005EXPRESS;Initial Catalog=StudentDB;Persist Security Info=True;User ID=ssword=sa;20myAdapter.Update(myDataSet, myStudentTable);myConnection.Close();this.btnUpdate1.Enabled = false;this.btnUpdate2.Enabled = false;stringStr = Data Source=.SQL2005EXPRESS;Initial/SqlConnection myConnectio

14、n =new SqlConnection(Str);/myConnection.Open();SqlDataAdapter myAdapter = new myConnection);SqlDataAdapter(SELECT * FROM student,mandBuilder myBuilder = dBuilder(myAdapter);DataSet myDataSet = new DataSet();myAdapter.Fill(myDataSet, myStudentTable);Dolumn mykeys = new Dolumn1;findRowage = Convert.To

15、32(this.txbAge.Text);myAdapter.Update(myDataSet, myStudentTable);myConnection.Close(); this.btnUpdate1.Enabled = false; this.btnUpdate2.Enabled = false;private void txbName_TextChanged(objecthis.btnUpdate1.Enabled = true;this.btnUpdate2.Enabled = true;private void txbAge_TextChanged(objecthis.btnUpdate1.Enabled = true;this.btnUpdate2.Enabled = true;der, EventArgs e)der, EventArgs e)21DataRow findRow = myDataSet.TablesmyStudentTable.Rows.Find(this.txbID.Text);if (findRow != null)= this

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论