} else { MessageBox.Show(\对不起,输入用户名或密码有误\aConnection.Close(); } } 2, 添加用户 private void button1_Click(object sender, EventArgs e) { OleDbConnection aConnection = new OleDbConnection(\Application.StartupPath + \ aConnection.Open(); ///打开数据库 String SQLString = \values('\设置sql查询语句 OleDbDataAdapter myadapter = new OleDbDataAdapter(SQLString, aConnection); ///创建适配器,执行sql查询 DataSet ds = new DataSet(); ///建立数据集 myadapter.Fill(ds); ///将查询结果 加入 ds中 aConnection.Close(); DataRefresh();//刷新程序 } 3, 修改密码 private void button2_Click(object sender, EventArgs e) { OleDbConnection aConnection = new OleDbConnection(\Application.StartupPath + \ aConnection.Open(); ///打开数据库 String SQLString = \textBox2.Text + \设置sql查询语句 OleDbDataAdapter myadapter = new OleDbDataAdapter(SQLString, aConnection); ///创建适配器,执行sql查询 DataSet ds = new DataSet(); ///建立数据集 myadapter.Fill(ds); ///将查询结果 加入 ds中 aConnection.Close(); DataRefresh();//刷新程序 } 4, 删除用户 private void button3_Click(object sender, EventArgs e) { OleDbConnection aConnection = new OleDbConnection(\Application.StartupPath + \ aConnection.Open(); ///打开数据库 String SQLString = \Uname='\设置sql查询语句 OleDbDataAdapter myadapter = new OleDbDataAdapter(SQLString, aConnection); ///创建适配器,执行sql查询 DataSet ds = new DataSet(); ///建立数据集 myadapter.Fill(ds); ///将查询结果 加入 ds中 aConnection.Close(); DataRefresh();//刷新程序 } 5, 查询 private void 查询_Click(object sender, EventArgs e) { //查询 string filename = System.Windows.Forms.Application.StartupPath + \野外记录.xls\获得完全路径 string strConnection = \source=\'\定义连接要求 OleDbConnection conn = new OleDbConnection(strConnection); conn.Open(); ///打开数据库 string query = \野外记录表$] where 照片号='\+ textBox1.Text+\ DataSet ds = new DataSet(); OleDbDataAdapter myadapter = new OleDbDataAdapter(query, conn); myadapter.Fill(ds); textBox1.Text = ds.Tables[0].Rows[0][\照片号\ textBox2.Text = ds.Tables[0].Rows[0][\经度\ textBox3.Text = ds.Tables[0].Rows[0][\纬度\ textBox4.Text = ds.Tables[0].Rows[0][\天气\ textBox5.Text = ds.Tables[0].Rows[0][\日期\ textBox6.Text = ds.Tables[0].Rows[0][\描述\ textBox7.Text = ds.Tables[0].Rows[0][\记录员\ dataGridView1.DataSource = ds.Tables[0];//将dataGridView1 与ds 中的内容连接起来 conn.Close(); conn.Dispose(); } 6, 修改记录 private void 修改记录_Click(object sender, EventArgs e) { string filename = System.Windows.Forms.Application.StartupPath + \野外记录.xls\获得完全路径 string strConnection = \ \定义连接要求 OleDbConnection conn = new OleDbConnection(strConnection); conn.Open(); DataSet ds = new DataSet(); String SQLString = \野外记录表$] set 经度=\textBox2.Text.Trim() + \纬度= \天气='\textBox4.Text + \日期='\描述='\textBox6.Text.Trim().ToString() + \记录员='\where 照片号 ='\ OleDbDataAdapter myadapter = new OleDbDataAdapter(SQLString, conn); myadapter.Fill(ds); MessageBox.Show(\修改成功!\ } 7, 查询所有 private void 查询所有_Click(object sender, EventArgs e) { try { string filename = System.Windows.Forms.Application.StartupPath + \野外记录.xls\获得完全路径 string strConnection = \properties='excel 8.0;HDR=YES;IMEX=1 '\定义连接要求 OleDbConnection conn = new OleDbConnection(strConnection); conn.Open(); String SQLString = \野外记录表$]\ DataSet ds = new DataSet(); OleDbDataAdapter myadapter = new OleDbDataAdapter(SQLString, conn); myadapter.Fill(ds); dataGridView1.DataSource = ds.Tables[0];//将dataGridView1 与ds 中的内容连接起来 conn.Close(); } catch (Exception msg) { throw new Exception(msg.ToString()); } } 8, 添加记录 private void 添加记录_Click(object sender, EventArgs e) { string filename = System.Windows.Forms.Application.StartupPath + \野外记录.xls\获得完全路径 string strConnection = \source=\ \定义连接要求 OleDbConnection conn = new OleDbConnection(strConnection); conn.Open(); DataSet ds = new DataSet(); //String SQLString = \ [野外记录表$](照片号,经度,纬度,天气,日期,描述,记录员) VALUES('\textBox1.Text.Trim() + \textBox3.Text.Trim() + \\实地观测类别描述 String SQLString = \ [野外记录表$](照片号,经度,纬度,天气,日期,描述,记录员)values('\textBox2.Text + \
期末实践 - 设计报告 - 选题版(2)
2019-04-23 13:31
期末实践 - 设计报告 - 选题版(2).doc
将本文的Word文档下载到电脑
下载失败或者文档不完整,请联系客服人员解决!