zoukankan      html  css  js  c++  java
  • 数据库单个表的数据删除,access,sql2000,asp.net2.0

    图示:数据库单个表的数据删除,access,sql2000,asp.net2.0

    ===========form1的代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.OleDb;
    using System.Data.SqlClient;

    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                //下载dotnetfx2.0
                string neturl = "http://blog.sina.com.cn/s/blog_5e2bdcdb0100dp89.html";
                System.Diagnostics.Process.Start(neturl);
            }

            private void button1_Click(object sender, EventArgs e)
            {
                //开始删除
                string time1 = this.dateTimePicker1.Text.ToString().Replace('年', '-').Replace('月', '-').Replace('日', ' ') + "23:00:00";
                DialogResult result = MessageBox.Show("时间设定为"+ time1 +",确定删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (result == DialogResult.Yes)
                {
                   
                    if (this.radioButton1.Checked)
                      //acc,数据库就有问题了,数据库内的时间数据并不是以时间格式存放,因此无法使用< 小于号进行比较
                        string filepath = this.textBox_acc.Text.ToString().Trim();
                      
                        int exe = 0;
                        try
                        {
                            string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Persist Security Info=True";
                            OleDbConnection conn = new OleDbConnection(strConnection);
                            conn.Open();

                            string sql = string.Format("delete from GameInfo where Game_StartTime < #{0}#", time1);
                            OleDbCommand cmd = new OleDbCommand(sql, conn);
                            exe = cmd.ExecuteNonQuery();

                            conn.Close();
                            conn.Dispose();
                           
                        }
                        catch (Exception ex)
                        {
                            this.label_call.Text = ex.ToString().Substring(30, 50);
                            return;
                        }
                        if (exe >= 1)
                        {
                            this.label_call.Text = "删除成功";
                            return;
                        }
                        else
                        {
                            this.label_call.Text = "没有找到任何匹配数据";
                            return;
                        }
                      

                    }
                    else
                     //sql
                        string time = this.dateTimePicker1.Text.ToString().Replace('年', '-').Replace('月', '-').Replace('日', ' ') + "23:00:00";
                        string sqlname = this.textBox_sqlname.Text.ToString().Trim();
                        string user = textBox_user.Text.ToString().Trim();
                        string pass = this.textBox_pass.Text.ToString().Trim();


                        int exe = -1;
                        SqlCommand com = null;
                        try
                        {
                            string ConSqlString = string.Format("Server=127.0.0.1;database={0};uid={1};pwd={2};", sqlname, user, pass);
                            SqlConnection conn = new SqlConnection();

                            conn.ConnectionString = ConSqlString;
                            conn.Open();

                            string sql = string.Format("delete from GameInfo where Game_StartTime < '{0}'",time);
                            com = new SqlCommand(sql, conn);
                            exe = com.ExecuteNonQuery();

                            conn.Close();
                            conn.Dispose();

                        }
                        catch (Exception ex)
                        {
                            this.label_call.Text = ex.ToString().Substring(30,50);
                        }
                        if (exe >= 1)
                        {
                            this.label_call.Text = "删除成功";
                        }
                        else
                        {
                            this.label_call.Text = "没有找到任何行";
                        }
                    }
                   
                }
                else
                {
                    return;
                }

            }

            private void button2_Click(object sender, EventArgs e)
            {
                //选择acc数据库文件
                OpenFileDialog fileDialog = new OpenFileDialog();
                fileDialog.ShowDialog();
                this.textBox_acc.Text = fileDialog.FileName.ToString();
            }

            private void radioButton1_CheckedChanged(object sender, EventArgs e)
            {
                if (this.radioButton1.Checked)
                  //acc
                    this.textBox_acc.Enabled = true;
                    this.button_acc.Enabled = true;

                    this.textBox_sqlname.Enabled = false;
                    this.textBox_user.Enabled = false;
                    this.textBox_pass.Enabled = false;
                }
                else
                 //sql
                    this.textBox_acc.Enabled = false;
                    this.button_acc.Enabled = false;

                    this.textBox_sqlname.Enabled = true;
                    this.textBox_user.Enabled = true;
                    this.textBox_pass.Enabled = true;
                }
            }

            private void radioButton2_CheckedChanged(object sender, EventArgs e)
            {
                if (this.radioButton1.Checked)
                  //acc
                    this.textBox_acc.Enabled = true;
                    this.button_acc.Enabled = true;
                }
                else
                 //sql
                    this.textBox_acc.Enabled = false;
                    this.button_acc.Enabled = false;
                }
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                //初始状态
                this.textBox_sqlname.Enabled = false;
                this.textBox_user.Enabled = false;
                this.textBox_pass.Enabled = false;
            }

            private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                //点击弹出新form
                Form2 f2 = new Form2();
                f2.Show();
            }

            private void label7_Click(object sender, EventArgs e)
            {

            }
        }
    }

     

     

    友情链接 : 遨游官方论坛:http://www.7v7.cn/?fromuid=177

  • 相关阅读:
    java 获取未知枚举的集合(get unknown enum list)
    解析Disruptor:写入ring buffer
    解析Disruptor:拼接依赖
    Python3.x在linux下print中文问题
    Python3源码方式编译
    正则表达式学习
    PHP传值和传引用、传地址的区别
    php中关于sizeof()函数
    [原]JointJS流程图
    [原]OpeanLayers3 For ArcGIS MapServer
  • 原文地址:https://www.cnblogs.com/binlunia/p/11267775.html
Copyright © 2011-2022 走看看