C#实验报告Word文档格式.docx
- 文档编号:17291743
- 上传时间:2022-11-30
- 格式:DOCX
- 页数:16
- 大小:1.61MB
C#实验报告Word文档格式.docx
《C#实验报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《C#实验报告Word文档格式.docx(16页珍藏版)》请在冰豆网上搜索。
(2).做一个通讯录界面,用来查询删除添加修改个人通讯录。
三.实验步骤
创建Windows应用程序
启动VS2005创建windows应用程序并起名为通讯录001进入编辑页,添加需要控件做一个登陆界面最终效果图为:
然后编辑代码使登录窗体正常运行
连接数据库启动SqlServer连接服务器
在Windows项目中连接数据库
添加Windows窗体向里面添加一些需要控件并且将所设计的表格拖入Form2
到此步就可以运行程序查询通信录信息
然后设计修改信息Form5窗体并且添加各种需要控件
把40906030222学生需要修改的信息填入此窗体点击确认修改显示修改后出现的修改后信息是
然后设计添加信息Form3窗体,把添加信息输入此窗体确认添加
添加后的窗体在Form2中显示为
设计删除信息添加删除Form4窗体并输入需要删除学生的学号就可以将这一行全部删除
实验代码编辑
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Windows.Forms;
namespace通讯录001
{
staticclassProgram
{///<
summary>
///应用程序的主入口点。
///<
/summary>
[STAThread]
staticvoidMain()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(newForm1());
}
}
1.登陆代码编辑
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
publicpartialclassForm1:
Form
publicForm1()
InitializeComponent();
privatevoidbutton1_Click(objectsender,EventArgse)
if(textBox1.Text==string.Empty||textBox2.Text==string.Empty)
MessageBox.Show("
信息不完整!
"
"
登录"
);
return;
if(!
textBox1.Text.Equals("
康萌萌"
)||!
textBox2.Text.Equals("
KM0810"
))
用户名或密码不正确!
else
登录成功!
newForm2().Show();
privatevoidForm1_Load(objectsender,EventArgse)
}
privatevoidbutton2_Click_1(objectsender,EventArgse)
textBox1.Clear();
textBox2.Clear();
privatevoidtextBox2_TextChanged(objectsender,EventArgse)
窗体2设计所需代码
usingSystem.Data.SqlClient;
publicpartialclassForm2:
publicForm2()
privatevoidtable_1BindingNavigatorSaveItem_Click(objectsender,EventArgse)
this.Validate();
this.table_1BindingSource.EndEdit();
this.table_1TableAdapter.Update(this.kMDataSet1.Table_1);
privatevoidForm3_Load(objectsender,EventArgse)
//TODO:
这行代码将数据加载到表“kMDataSet1.Table_1”中。
您可以根据需要移动或移除它。
this.table_1TableAdapter.Fill(this.kMDataSet1.Table_1);
privatevoid姓名TextBox_TextChanged(objectsender,EventArgse)
privatevoid年龄TextBox_TextChanged(objectsender,EventArgse)
privatevoid性别Label_Click(objectsender,EventArgse)
privatevoidbutton1_Click(objectsender,EventArgse)
newForm5().Show();
this.Hide();
privatevoidbutton2_Click(objectsender,EventArgse)
newForm3().Show();
privatevoidbutton3_Click(objectsender,EventArgse)
newForm4().Show();
添加程序代码
privatevoidtable_1BindingNavigatorSaveItem_Click(objectsender,EventArgse)
privatevoid年龄TextBox_TextChanged(objectsender,EventArgse)
{
privatevoidbutton2_Click(objectsender,EventArgse)
删除程序代码
publicpartialclassForm4:
publicForm4()
stringconnString="
datasource=KM-PC\\SQLSERVER2005;
persistsecurityinfo=True;
initialcatalog=KM;
UserID=sa;
Password="
;
SqlConnectionconn=newSqlConnection(connString);
stringstr="
deletefromTable_1where学号='
+this.textBox1.Text+"
'
SqlCommandcmd=newSqlCommand(str,conn);
try
conn.Open();
inti=cmd.ExecuteNonQuery();
if(i==1)
删除成功"
提示信息"
删除除失败"
catch(SqlException)
异常发生"
finally
conn.Close();
确认修改程序代码
publicpartialclassForm5:
publicForm5()
privatevoidbutton1_Click(objectsender,EventArgse)
updateTable_1set姓名='
+this.textBox2.Text+"
性别='
+this.textBox3.Text+"
年龄='
+this.textBox4.Text+
"
联系电话='
+this.textBox5.Text+"
家庭住址='
+this.textBox6.Text+"
出生日期='
+this.textBox7.Text+"
联系地址='
+
this.textBox8.Text+"
QQ='
+this.textBox9.Text+"
所在院校='
+this.textBox10.Text+"
where学号='
+this.textBox1.Text+"
inti=cmd.ExecuteNonQuery();
if(i==1)
修改成功"
修改失败"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 实验 报告