您好,欢迎访问三七文档
数据库应用:*需要提交:1、创建的数据库以及每个项目的源文件;2、整个实验提交一份实验报告,含主要代码片断以及程序截图1.设计一个检验密码程序,当用户在文本框中输入密码按回车键时,如果用户输入密码正确,则在窗体上的标签中显示“欢迎你使用本系统!”,否则,显示“密码错误,请重新输入密码。”,若连续三次输入的密码都不正确,则在屏幕上显示一个消息框,并在消息框中提示信息“对不起,你不能使用本系统!”,然后结束本程序的执行。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace桌面3_1{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidtextBox1_TextChanged(objectsender,EventArgse){}privatevoidbutton1_Click(objectsender,EventArgse){inti=0;i=i+1;if(textBox1.Text==123){Graphicsg=panel1.CreateGraphics();g.Clear(Color.Gray);g.DrawString(欢迎登陆,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}else{if(i3){Graphicsg=panel1.CreateGraphics();g.Clear(Color.Gray);g.DrawString(密码错误,请重新输入密码。,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}else{Form2fm=newForm2();fm.Show();}Form2fm=newForm2();fm.Show();}}}}2.设计一个程序,查询飞往各城市的航班时间。功能是:在运行程序后,用户从列表框中选择一个城市名,然后,单击“查询”按钮,在文本框中显示航班的起飞时间。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace桌面3_2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){if(listBox1.GetSelected(0)){Graphicsg=panel1.CreateGraphics();g.Clear(Color.Gray);g.DrawString(起飞时间是9:27,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}if(listBox1.GetSelected(1)){Graphicsg=panel1.CreateGraphics();g.Clear(Color.Gray);g.DrawString(起飞时间是19:20,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}if(listBox1.GetSelected(2)){Graphicsg=panel1.CreateGraphics();g.Clear(Color.Gray);g.DrawString(起飞时间是22:07,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}}privatevoidForm1_Load(objectsender,EventArgse){listBox1.Items.Add(北京);listBox1.Items.Add(上海);listBox1.Items.Add(广州);}}}3.3.编写一个同学通信录程序:当在下拉列表框中选择某一同学的姓名后,能够在三个文本框中分别显示该同学的电话号码、邮政编码和住址。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace桌面3_3{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){}privatevoidcomboBox1_SelectedIndexChanged_1(objectsender,EventArgse){if(comboBox1.SelectedItem==张三){{Graphicsg=panel1.CreateGraphics();g.Clear(Color.White);g.DrawString(电话号码:13248258925,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}{Graphicsa=panel2.CreateGraphics();a.Clear(Color.White);a.DrawString(邮政编码:201209,newFont(宋体,9),newSolidBrush(Color.Black),0,0);a.Dispose();}{Graphicss=panel3.CreateGraphics();s.Clear(Color.White);s.DrawString(住址:河东女寝,newFont(宋体,9),newSolidBrush(Color.Black),0,0);s.Dispose();}}if(comboBox1.SelectedItem==李四){{Graphicsg=panel1.CreateGraphics();g.Clear(Color.White);g.DrawString(电话号码:1520957363,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}{Graphicsg=panel2.CreateGraphics();g.Clear(Color.White);g.DrawString(邮政编码:051430,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}{Graphicsg=panel3.CreateGraphics();g.Clear(Color.White);g.DrawString(住址:河东男寝,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}}if(comboBox1.SelectedItem==王五){{Graphicsg=panel1.CreateGraphics();g.Clear(Color.White);g.DrawString(电话号码:150017771946,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}{Graphicsg=panel2.CreateGraphics();g.Clear(Color.White);g.DrawString(邮政编码:050000,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}{Graphicsg=panel3.CreateGraphics();g.Clear(Color.White);g.DrawString(住址:河南女寝,newFont(宋体,9),newSolidBrush(Color.Black),0,0);g.Dispose();}}}}}4.文件you.mdb是Access数据库文件。编写程序,运行该程序,可以在窗体的四个角上显示you.mdb数据库中you数据表的第一条记录中的一个you字段中的内容。要求显示的文字大小和颜色互不相同。另外,在窗体的中间显示你的姓名。程序的显示可以随you字段中的内容的变化而变化。(you.mdb数据库自建)usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.Common;namespace_4{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){stringSelectString=select*fromyou;oleDbDataAdapter1.SelectCommand.CommandText=SelectString;dataSet11.Clear();oleDbDataAdapter1.Fill(dataSet11,you);label1.Text=dataSet11.Tables[0].Rows[0][0].ToString();label2.Text=dataSet11.Tables[0].Rows[0][0].ToString();label3.Text=dataSet11.Tables[0].Rows[0][0].ToString();label4.Text=dataSet11.Tables[0].Rows[0][0].ToString();}5.建一个到sqlserver数据库northwind的连接,并将customers表中的ContactName字段的值添加到列表框中。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespaceData05{publicpartialclassForm1:Form{stringstrCon;SqlConnectionsqlCon;publicForm1(){Initi
本文标题:c#实训基础题
链接地址:https://www.777doc.com/doc-4692087 .html