SQLHelper应用

private void News_Load(object sender, EventArgs e)
        {
            this.Size = new Size (712,359);
            //加载数据源
            string str = string.Format(@"select * from News");
            DataTable dt = DBHelperL.ExcuteQuery(str);
            this.dataGridView1.DataSource=dt;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //显示时间
            this.lab_time.Text = DateTime.Now.ToString();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //删除的代码
           string id= this.textBox1_id.Text .Trim ();
           string str = string.Format(@"delete from News where id='{0}'",id );
           object o = DBHelperL.ExcuteBYSQL(str );
           int returnno = Convert.ToInt32(o.ToString ());
           if (returnno == 1)
           {
               MessageBox.Show(" Data Is Delete Succeed !!!");
           }
           else 
           {
               MessageBox.Show("Sorry You Not Succeed !!!");
           }
        }

        private void label4_Click(object sender, EventArgs e)
        {
            //查询的代码
            string name = this.tb_set.Text.Trim();
            if (name !="")
            {
                string str = string.Format(@"select * from News where name='{0}'",name );
                DataTable dt = DBHelperL.ExcuteQuery(str);
                this.dataGridView1.DataSource = dt;
            }
            else
            {
                string str = string.Format(@"select * from News");
                DataTable dt = DBHelperL.ExcuteQuery(str);
                this.dataGridView1.DataSource = dt;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
           //界面的大小
            this.Size = new Size(712,446);
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //显示选中的数据
            this.textBox1_id.Text  = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            this.textBox2_name .Text =this .dataGridView1 .Rows [e.RowIndex ].Cells [1].Value .ToString ();
            this.textBox3_sex.Text = this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            this.textBox4_age.Text = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
            this.textBox5_birth.Text = this.dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
            this.textBox6_phone.Text = this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();

        }

        private void News_FormClosing(object sender, FormClosingEventArgs e)
        {
            //退出的代码
            System.Environment.Exit(1);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //修改的代码
            string id = this.textBox1_id.Text.Trim();
            string name = this.textBox2_name.Text.Trim();
            string sex = this.textBox3_sex.Text.Trim();
            string age = this.textBox4_age.Text.Trim();
            string birth = this.textBox5_birth.Text.Trim();
            string phone = this.textBox6_phone.Text.Trim();
            string str = string.Format(@"UPDATE [News] SET [Name] = '{0}' ,[Sex] = '{1}',[Age] = '{2}',[Birth] = '{3}',[Phone] = '{4}'WHERE id='{5}'",name ,sex ,age ,birth ,phone ,id );
            Object o = DBHelperL.ExcuteBYSQL(str);
            int returnno = Convert.ToInt32(o.ToString ());
            if(returnno ==1)
            {
                MessageBox.Show(" Data Is Update Succeed !!!");
            }
            else
            {
                MessageBox.Show("Sorry You Not Succeed !!!");
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值