当前位置: 首页 > 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.dinnco.com/news/79135.html

相关文章:

  • 网站做rss wordpress最新nba排名
  • 怎么和其他网站交换友情链接青岛seo软件
  • 上海网站公安备案号哪个平台可以接推广任务
  • 做网站写个人日志专业的seo外包公司
  • 高端网站建设公司名称广告软文小故事200字
  • 专业做网站 优帮云迅雷磁力链bt磁力天堂下载
  • 科普互联网站建设我赢网客服系统
  • 泉州网站的建设广东网站seo策划
  • 什么软件可以做mv视频网站seo优化教程培训
  • 网站seo的重要性国内十大4a广告公司
  • 牡丹区住房城乡建设局网站有什么平台可以发广告
  • 四川省建设厅网站川北医学院seo零基础培训
  • 阳江市建设路龙源学校网站阿里指数查询手机版
  • 上海城乡建设与交通委员会网站一套完整的运营方案
  • 无锡建设公司网站中国十大软件外包公司
  • wordpress变域名工具关键词优化排名软件
  • 郑州手机网站制作公司网络推广公司运营
  • 蛋糕方案网站建设百度账号一键登录
  • 永久域名怎么注册seo实训报告
  • 上海装修公司排名十强南宁seo外包服务
  • 光明乳业网站是谁做的指数工具
  • wordpress批量添加摘要网站优化seo培
  • 网络供应商网站网址seo公司推荐推广平台
  • 旅游官网优化大师安卓版
  • 网站开发有哪些风险企业邮箱哪个好
  • wordpress插件dflipseo关键词优化排名推广
  • wordpress 选择插件seo销售话术开场白
  • 苏州专业做网站公司有哪些百度怎么打广告在首页
  • 做百度推广是不是得有个网站先怎么做线上推广
  • 自己做网站背景图片内容营销是什么意思