WindowsFormsApplication
来源:互联网 发布:php和asp.net哪个好 编辑:程序博客网 时间:2024/05/21 10:31
只是不想把我的实验科目永远只是停留在我的电脑上 如果你是学这行技术的可以借鉴也可以提出批评 如果你不是学这个的 也可以帮你看看windows桌面窗体软件的一些简单的原理 技术的天堂因青春的激情而狂热 动人的音符因小伙伴们的支持而跳动对于界面UI 微软那套是可以直接把控件拖出来就用 这里就不多说(这里是用vs2010开发)From1.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void getConn() { SqlConnection sqlConn = null; try { sqlConn = new SqlConnection("Data Source=.\\SQLEXPRESS; AttachDbFilename = D:\\student.mdf; Integrated Security = True;Connect Timeout=30;User Instance=True"); sqlConn.Open(); SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlConn; sqlCmd.CommandText = "select * from student"; SqlDataReader sqlReader = sqlCmd.ExecuteReader(); while (sqlReader.Read()) { listBox1.Items.Add(Convert.ToString(sqlReader["number"]) + Convert.ToString(sqlReader["name"]) + Convert.ToString(sqlReader["sex"]) + Convert.ToString(sqlReader["age"]) + Convert.ToString(sqlReader["special"])); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { sqlConn.Close(); } } public void getExecuteReader() { SqlConnection sqlConn = null; try { sqlConn = new SqlConnection("Data Source=.\\SQLEXPRESS; AttachDbFilename = D:\\student.mdf; Integrated Security = True;Connect Timeout=30;User Instance=True"); sqlConn.Open(); SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlConn; string queryString1 = "Select * from student where number = '"; string searchNumberValue1 = textBox1.Text; queryString1 += searchNumberValue1 + "'"; SqlCommand sqlCommand1 = new SqlCommand(queryString1, sqlConn); SqlDataReader read1 = sqlCommand1.ExecuteReader(); while (read1.Read()) { textBox2.Text= Convert.ToString(read1["name"]); textBox3.Text = Convert.ToString(read1["sex"]); textBox4.Text = Convert.ToString(read1["age"]); textBox5.Text = Convert.ToString(read1["special"]); } read1.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { sqlConn.Close(); } } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { getExecuteReader(); } private void button2_Click(object sender, EventArgs e) { getConn(); } private void button3_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; } private void button4_Click(object sender, EventArgs e) { //listBox1.Items.RemoveAt(0);//删一个下标为零的数据 //listBox1.Items.Remove();//给定要删源数据 listBox1.Items.Clear(); listBox1.Refresh(); } }}
我们运行程序后点击测试数据按钮 测试我们的数据库中的数据已经添加进来
测试清空数据按钮
我们的student数据库中的数据
我们再查找一组数据
0 0
- WindowsFormsApplication
- 一个比较完整的WindowsFormsApplication实现
- 【SharpGL】VS WindowsFormsApplication 项目 SharpGL配置
- 关于将WindowsFormsApplication发布到远程服务器的一些总结
- [Unity3D]Unity3D游戏开发之仿仙剑奇侠传角色死亡效果实现
- 数据持久化(二)-----Sqlite
- (十五)-如何实现拍照功能
- 重装系统后ORACLE数据库恢复的方法
- android如何释放图片缓存
- WindowsFormsApplication
- Qt socket中怎么传结构体?
- js和html转义
- (十六)-将Image转换为Base64
- HDU 2795 Billboard(线段树)
- 重建控制文件--alter database backup controlfile to trace
- 【rollback】
- POJ 1182食物链(并查集)
- 利用纯CSS3实现超立体的3D图片侧翻倾斜效果