当前位置: 首页 > news >正文

怎么做属于自己的网站中国国家数据统计网

怎么做属于自己的网站,中国国家数据统计网,手机站模板,烟台专业网站建设公司版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。 需要北风数据库的请留言自己的信箱。 本节中将通过实例综合展示对数据表的查询、增加、修改和删除。 【例 19.16】【项目&#xf…

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。

需要北风数据库的请留言自己的信箱。

本节中将通过实例综合展示对数据表的查询、增加、修改和删除。

【例 19.16【项目:code19-016】雇员信息管理。

本例演示了对北风数据库中雇员表中的雇员信息进行管理,实现对雇员信息(由于原表信息太多,有省略)的增加、修改和删除,其中修改提供了两种方式。

窗体设计如下图所示:

图19-36 窗体设计

详细代码如下:

        OleDbConnection conn;

        string currentName;

        private void Form1_Load(object sender, EventArgs e)

        {

            //建立OleDbConnection对象实例

            conn = new OleDbConnection();

            //32位程序使用此语句

            conn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;data source=C:\\lessons\\Northwind.mdb;";

            //64位程序使用此语句

            //conn.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;data source=C:\\lessons\\Northwind.mdb;";

            conn.Open();

            listEmployee();

        }

 

        //将所有雇员全名加入到cbEmployee中

        private void listEmployee()

        {

            cbEmployee.Items.Clear();

            OleDbCommand command = new OleDbCommand();

            command.CommandText = "select 雇员ID,(姓氏+名字) as 姓名 from 雇员";

            command.Connection = conn;

            OleDbDataReader reader;

            reader = command.ExecuteReader(CommandBehavior.SingleResult);

 

            if( reader.HasRows)

            {

                while (reader.Read())

                    cbEmployee.Items.Add(reader["姓名"]);

                cbEmployee.SelectedIndex = 0;

            }

        }

 

 

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)

        {

            conn.Close();

        }

 

        //增加雇员信息

        private void btnAdd_Click(object sender, EventArgs e)

        {

            btnOk.Visible = true;

            btnCancel.Visible = true;

            Panel1.Visible = true;

            Panel1.Left = cbEmployee.Left;

            Panel1.Top = 10;

            cbEmployee.Visible = false;

 

            //清空文本框内的所有数据

            txtDuties.Text = "";

            txtAppellation.Text = "";

            dtpBirthday.Value = DateTime.Now;

            dtpEmployDay.Value = DateTime.Now;

            txtCountry.Text = "";

            txtCity.Text = "";

            txtArea.Text = "";

            txtAddress.Text = "";

            txtZipcode.Text = "";

            txtPhone.Text = "";

        }

 

        //增加雇员信息实际是btnOk按钮完成

        private void btnOk_Click(object sender, EventArgs e)

        {

            OleDbCommand command = new OleDbCommand();

            command.CommandText = "insert into 雇员(姓氏,名字,职务,尊称,出生日期,雇用日期,地址,城市,地区,邮政编码,国家,家庭电话)" +

                                   "values('" + txtSurname.Text + "','" +

                                        txtName.Text + "','" +

                                        txtDuties.Text + "','" +

                                        txtAppellation.Text + "','" +

                                        dtpBirthday.Value + "','" +

                                        dtpEmployDay.Value + "','" +

                                        txtAddress.Text + "','" +

                                        txtCity.Text + "','" +

                                        txtArea.Text + "','" +

                                        txtZipcode.Text + "','" +

                                        txtCountry.Text + "','" +

                                        txtPhone.Text + "')";

            command.Connection = conn;

            try

            {

                command.ExecuteNonQuery();

                MessageBox.Show("新增成功!");

                string fullname = txtSurname.Text + txtName.Text;

                cbEmployee.Items.Add(fullname);

                currentName = fullname;

            }          

            catch (Exception ex)

            {

                MessageBox.Show("新增失败:" + ex.Message);

            }

 

            btnOk.Visible = false;

            btnCancel.Visible = false;

            Panel1.Visible = false;

            cbEmployee.Visible = true;

            //显示雇员信息

            getEmployeeInfo(currentName);

        }

 

        //取消新增雇员

        private void btnCancel_Click(object sender, EventArgs e)

        {

            btnOk.Visible = false;

            btnCancel.Visible = false;

            Panel1.Visible = false;

            cbEmployee.Visible = true;

            //显示雇员信息

            getEmployeeInfo(currentName);

        }

 

        //修改雇员信息方式一

        private void btnEdit1_Click(object sender, EventArgs e)

        {

            OleDbCommand command = new OleDbCommand();

            command.CommandText = "update 雇员 set 职务='" + txtDuties.Text +

                                    "',尊称='" + txtAppellation.Text +

                                    "',出生日期='" + dtpBirthday.Value +

                                    "',雇用日期='" + dtpEmployDay.Value +

                                    "',国家='" + txtCountry.Text +

                                    "',城市='" + txtCity.Text +

                                    "',地区='" + txtArea.Text +

                                    "',地址='" + txtAddress.Text +

                                    "',邮政编码='" + txtZipcode.Text +

                                    "',家庭电话='" + txtPhone.Text +

                                    "' where 姓氏+名字='" + cbEmployee.Text + "'";

            command.Connection = conn;

            try

            {

                command.ExecuteNonQuery();

                MessageBox.Show("修改成功!");

            }

           

            catch ( Exception ex)

            {

                MessageBox.Show("修改失败:" + ex.Message);

            }

        }

 

        //修改雇员信息方式二

        private void btnEdit2_Click(object sender, EventArgs e)

        {

            OleDbCommand command = new OleDbCommand();

            command.CommandText = "update 雇员 set 职务=?,尊称=?,出生日期=?," +

                                    "雇用日期=?," +

                                    "国家=?," +

                                    "城市=?," +

                                    "地区=?," +

                                    "地址=?," +

                                    "邮政编码=?," +

                                    "家庭电话=?" +

                                    " where 姓氏+名字=?";

            command.Parameters.Add("@Duties", OleDbType.VarChar);

            command.Parameters["@Duties"].Value = txtDuties.Text;

            command.Parameters.Add("@Appellation", OleDbType.VarChar);

            command.Parameters["@Appellation"].Value = txtAppellation.Text;

            command.Parameters.Add("@Birthday", OleDbType.Date);

            command.Parameters["@Birthday"].Value = dtpBirthday.Value;

            command.Parameters.Add("@EmployDay", OleDbType.Date);

            command.Parameters["@EmployDay"].Value = dtpEmployDay.Value;

            command.Parameters.Add("@Country", OleDbType.VarChar);

            command.Parameters["@Country"].Value = txtCountry.Text;

            command.Parameters.Add("@City", OleDbType.VarChar);

            command.Parameters["@City"].Value = txtCity.Text;

            command.Parameters.Add("@Area", OleDbType.VarChar);

            command.Parameters["@Area"].Value = txtArea.Text;

            command.Parameters.Add("@Address", OleDbType.VarChar);

            command.Parameters["@Address"].Value = txtAddress.Text;

            command.Parameters.Add("@Zipcode", OleDbType.VarChar);

            command.Parameters["@Zipcode"].Value = txtZipcode.Text;

            command.Parameters.Add("@Phone", OleDbType.VarChar);

            command.Parameters["@Phone"].Value = txtPhone.Text;

            command.Parameters.Add("@FullName", OleDbType.VarChar);

            command.Parameters["@FullName"].Value = cbEmployee.Text;

            command.Connection = conn;

            try

            {

                command.ExecuteNonQuery();

                MessageBox.Show("修改成功!");

            }

            catch (Exception ex)

            {

                MessageBox.Show("修改失败:" + ex.Message);

            }

        }

 

        //删除雇员信息

        private void btnDel_Click(object sender, EventArgs e)

        {

            OleDbCommand command = new OleDbCommand();

            command.CommandText = "delete * from 雇员 where 姓氏+名字='" + cbEmployee.Text + "'";

            command.Connection = conn;

            try

            {

                command.ExecuteNonQuery();

                MessageBox.Show("删除成功!");

                //删除后重新列出雇员

                listEmployee();

            }

 

            catch (Exception ex)

            {

                MessageBox.Show("删除失败:" + ex.Message);

            }

        }

 

        private void btnExit_Click(object sender, EventArgs e)

        {

            this.Close();

        }

 

        private void cbEmployee_SelectedIndexChanged(object sender, EventArgs e)

        {

            getEmployeeInfo(cbEmployee.Text);

        }

 

        //显示当前在cbEmployee中的雇员全名对应的雇员信息

        private void getEmployeeInfo(string fullname)

        {

            OleDbCommand odcommand = new OleDbCommand();

            odcommand.CommandText = "select * from 雇员 where 姓氏+名字='" + cbEmployee.Text + "'";

            odcommand.Connection = conn;

 

            OleDbDataReader reader ;

            reader = odcommand.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow);

            if (reader.HasRows)

            {

                reader.Read();

                txtDuties.Text = (string)reader["职务"];

                txtAppellation.Text = (string)reader["尊称"];

                dtpBirthday.Value =(DateTime) reader["出生日期"];

                dtpEmployDay.Value = (DateTime)reader["雇用日期"];

                txtCountry.Text = (string)reader["国家"];

                txtCity.Text = (string)reader["城市"];

                txtArea.Text = (string)reader["地区"];

                txtAddress.Text = (string)reader["地址"];

                txtZipcode.Text = (string)reader["邮政编码"];

                txtPhone.Text = (string)reader["家庭电话"];

            }

            else

                MessageBox.Show("错误的编号");

            reader.Close();

            currentName = cbEmployee.Text;

        }

运行结果如下图所示:

图19-37 新增雇员信息

学习更多vb.net知识,请参看vb.net 教程 目录

学习更多C#知识,请参看C#教程 目录

 

http://www.khdw.cn/news/60863.html

相关文章:

  • drupal 网站开发无锡营销型网站制作
  • 网站建设与管理基础及实训坚持
  • 免费移动网站建设公司网站如何seo
  • 德州网站优化公司百度指数api
  • 企业网站的基本形式不包括大型网站建设平台
  • 中江县建设局网站马鞍山seo
  • 做经销找厂家好的网站googleseo推广
  • wordpress被挂弹窗seo点击软件哪个好用
  • 浙江建设厅继续教育网站首页网店推广是什么
  • python 网站开发 prf网络营销模式下品牌推广途径
  • 唐山快速建站公司交换友链是什么意思
  • 网上服装商城网站建设方案策划书网络项目怎么推广
  • 怎样用dw做网站主页今日国际新闻头条
  • 什么平台可以接国外订单郑州seo排名扣费
  • 网站目录做二级域名网站关键词优化软件效果
  • 国外的电商网站百度推广官网登录
  • 律师做网站免费的app推广平台
  • 沈阳网站建设 成创百度指数在线查询工具
  • 怎样才能接外单 需做网站吗培训机构网站制作
  • 杭州网站建设页面百度网页版怎么切换
  • 网站怎么做域名实名认证企业网站网页设计
  • 网站建设与管理做什么互动营销是什么意思
  • 做外贸网站空间多少g网络营销与传统营销的整合
  • 微网站建设使用程序百度热搜关键词
  • 万网虚拟服务器怎么做网站内容优化seo深圳
  • 重庆 建网站百度推广的费用
  • 无锡网站建设 微信镇江搜索优化技巧
  • 手表网站哪个好沈阳百度推广哪家好
  • 免费网站建设入门seo臻系统
  • 南通营销网站制作外贸海外推广