Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            MySqlConnection mySqlConnectionRead = MysqlConn.getConnRead();
            MySqlCommand    mySqlCommand;
            String          sql;

            try
            {
                if (textBox3.Text != "")
                {
                    Convert.ToInt32(textBox3.Text);
                    sql = "select title,create_time,t.name from t_blog b,t_type t where b.type_id = t.id and b.id=" + textBox3.Text;
                }
                else
                {
                    sql = "select title,create_time,t.name from t_blog b,t_type t where b.type_id = t.id;";
                }
                mySqlCommand = new MySqlCommand(sql, mySqlConnectionRead);
                mySqlConnectionRead.Open();

                MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

                while (mySqlDataReader.Read())
                {
                    for (int i = 0; i <= 2; i++)
                    {
                        textBox2.Text += mySqlDataReader.GetString(i);
                        textBox2.Text += "  ";
                    }
                    textBox2.Text += "\r\n";
                }
            }
            catch (Exception ex)
            {
                textBox2.Text += "The data does not exists:" + ex.Message;
                textBox2.Text += "\r\n";
            }
            finally
            {
                MysqlConn.closeConnRead();
            }
        }
Exemple #2
0
        //上传blog数据表
        private void button5_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确定上传blog?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                MySqlConnection mySqlConnection     = MysqlConn.getConn();
                MySqlConnection mySqlConnectionRead = MysqlConn.getConnRead();
                MySqlCommand    mySqlCommand;
                MySqlDataReader mySqlDataReader;
                String          sql;
                int             type_id;
                try
                {
                    mySqlConnection.Open();
                    for (int i = 0; i < fileNameList.Count; i++)
                    {
                        mySqlConnectionRead.Open();
                        sql             = "select id from t_type where name='" + fileNameList[i].FatherDictionary + "'";
                        mySqlCommand    = new MySqlCommand(sql, mySqlConnectionRead);
                        mySqlDataReader = mySqlCommand.ExecuteReader();
                        mySqlDataReader.Read();
                        type_id = mySqlDataReader.GetInt32(0);
                        MysqlConn.closeConnRead();

                        sql = "insert into t_blog(create_time,update_time, content, title,user_id,type_id,  description) " +
                              "VALUES (@Createtime,@Updatetime,@Content,@Title,1,@Type_id,@Description);";
                        mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                        mySqlCommand.Prepare();

                        MySqlParameter p1 = new MySqlParameter("@Createtime", MySqlDbType.DateTime);
                        p1.Value = fileNameList[i].Createtime;
                        MySqlParameter p2 = new MySqlParameter("@Content", MySqlDbType.LongText);
                        p2.Value = fileNameList[i].Content;
                        MySqlParameter p3 = new MySqlParameter("@Title", MySqlDbType.VarChar);
                        p3.Value = fileNameList[i].Title;
                        MySqlParameter p4 = new MySqlParameter("@Type_id", MySqlDbType.Int64);
                        p4.Value = type_id;
                        MySqlParameter p5 = new MySqlParameter("@Description", MySqlDbType.VarChar);
                        MySqlParameter p6 = new MySqlParameter("@Updatetime", MySqlDbType.DateTime);
                        p6.Value = fileNameList[i].Updatetime;
                        p5.Value = fileNameList[i].Description;
                        mySqlCommand.Parameters.Add(p1);
                        mySqlCommand.Parameters.Add(p2);
                        mySqlCommand.Parameters.Add(p3);
                        mySqlCommand.Parameters.Add(p4);
                        mySqlCommand.Parameters.Add(p5);
                        mySqlCommand.Parameters.Add(p6);

                        if (mySqlCommand.ExecuteNonQuery() > 0)
                        {
                        }
                    }
                    MessageBox.Show("blog上传成功!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("上传失败:" + ex.Message);
                }
                finally
                {
                    MysqlConn.closeConn();
                }
            }
        }