当前位置: 首页>>代码示例>>C#>>正文


C# MySqlClient.MySqlConnection类代码示例

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnection的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnection类的具体用法?C# MySqlConnection怎么用?C# MySqlConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MySqlConnection类属于MySql.Data.MySqlClient命名空间,在下文中一共展示了MySqlConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InserirPedido

        public int InserirPedido(int numCliente, List<Item> pedido)
        {
            int NumPedido = 0;
            int idPedido = 0;
            MySqlConnection conn = new MySqlConnection(connectionString);
            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection = conn;
            conn.Open();

            cmd.CommandText = "Select Max(numero) + 1 from tb_Pedidos";
            NumPedido = int.Parse(cmd.ExecuteScalar().ToString());

            cmd.CommandText = "Insert into tb_Pedidos (numero, id_cliente, data) Values(" + NumPedido + "," + numCliente + ", sysdate()); select Max(id) from tb_Pedidos;";
            idPedido = int.Parse(cmd.ExecuteScalar().ToString());

            foreach (Item item in pedido)
            {
                cmd.CommandText = "insert into tb_items (nome, descricao, preco, quantidade, id_pedido, urlImagem) Values ('" + item.descricao + "', Null,"+ item.preco.ToString().Replace(",",".") + "," + item.quantidade + "," + idPedido + ", Null);";
                cmd.ExecuteNonQuery();
            }

            conn.Close();

            return NumPedido;
        }
开发者ID:JulioSI,项目名称:TP_Carefour,代码行数:26,代码来源:PedidoDAO.cs

示例2: Update

        /// <summary> 
        /// 修改数据 
        /// </summary> 
        /// <param name="entity"></param> 
        /// <returns></returns> 
        public int Update(Policy entity)
        {
            string sql = "UPDATE  tb_policy SET [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],";
            sql = sql + " [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected] where [email protected] ";

            //string sql = "UPDATE cimuser SET [email protected] WHERE [email protected]";
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@agentType", entity.agentType);
                command.Parameters.AddWithValue("@sequence", entity.sequence);
                command.Parameters.AddWithValue("@subject", entity.subject);
                command.Parameters.AddWithValue("@content", entity.content);
                command.Parameters.AddWithValue("@sender", entity.sender);
                command.Parameters.AddWithValue("@attachment", entity.attachment);
                command.Parameters.AddWithValue("@attachmentName", entity.attachmentName);
                command.Parameters.AddWithValue("@creatTime", entity.creatTime);
                command.Parameters.AddWithValue("@type", entity.type);
                command.Parameters.AddWithValue("@validateStartTime", entity.validateStartTime);
                 command.Parameters.AddWithValue("@validateEndTime", entity.validateEndTime);
                command.Parameters.AddWithValue("@isValidate", entity.isValidate);
                command.Parameters.AddWithValue("@isDelete", entity.isDelete);
                command.Parameters.AddWithValue("@deleteTime", entity.deleteTime);
                command.Parameters.AddWithValue("@toAll", entity.toAll);
                int i = command.ExecuteNonQuery();
                mycn.Close();
                mycn.Dispose();
                return i;
            }
        }
开发者ID:ZhouAnPing,项目名称:Mail,代码行数:36,代码来源:PolicyDao.cs

示例3: Button_click

        protected void Button_click(object sender, EventArgs e)
        {
            MySqlConnection bazaPovezava = new MySqlConnection(bazaConnString);
            try
            {
                bazaPovezava.Open();
                string SQLcommand = "INSERT INTO User(username, firstname, lastname, password, email, city, country) VALUES(?un, ?fn, ?ln, ?pw, ?em, ?ci, ?co);";
                MySqlCommand bazaUkaz = new MySqlCommand(SQLcommand, bazaPovezava);
                bazaUkaz.Parameters.Add(new MySqlParameter("?un", username.Text));
                bazaUkaz.Parameters.Add(new MySqlParameter("?fn", firstname.Text));
                bazaUkaz.Parameters.Add(new MySqlParameter("?ln", surname.Text));
                bazaUkaz.Parameters.Add(new MySqlParameter("?pw", pass.Text));
                bazaUkaz.Parameters.Add(new MySqlParameter("?em", email.Text));
                bazaUkaz.Parameters.Add(new MySqlParameter("?ci", city.Text));
                bazaUkaz.Parameters.Add(new MySqlParameter("?co", country.Text));

                bazaUkaz.ExecuteNonQuery();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                bazaPovezava.Close();
            }
        }
开发者ID:Kokanm,项目名称:eClassroomASP.NET,代码行数:27,代码来源:create.aspx.cs

示例4: CreateStaff

 internal void CreateStaff(Staff staff)
 {
     using (MySqlConnection conn = new MySqlConnection(PredatorConstants.CONNECTION_STRING))
     {
         if (MySqlConnectionManager.OpenConnection(conn))
         {
             string commandText =
     @"INSERT INTO staff (fName, lName, username, password, email, accessLevel, creationDate)
     VALUES(@FNAME, @LNAME, @USERNAME, @PASSWORD, @EMAIL, @ACCESSLEVEL, @CREATIONDATE)";
             MySqlCommand command = new MySqlCommand(commandText, conn);
             command.Parameters.Add("@FNAME", MySqlDbType.VarChar); ;
             command.Parameters["@FNAME"].Value = staff.fName;
             command.Parameters.Add("@LNAME", MySqlDbType.VarChar);
             command.Parameters["@LNAME"].Value = staff.lName;
             command.Parameters.Add("@USERNAME", MySqlDbType.VarChar);
             command.Parameters["@USERNAME"].Value = staff.username;
             command.Parameters.Add("@PASSWORD", MySqlDbType.VarChar);
             command.Parameters["@PASSWORD"].Value = staff.password;
             command.Parameters.Add("@EMAIL", MySqlDbType.VarChar);
             command.Parameters["@EMAIL"].Value = staff.email;
             command.Parameters.Add("@ACCESSLEVEL", MySqlDbType.Int32);
             command.Parameters["@ACCESSLEVEL"].Value = staff.accessLevel;
             command.Parameters.Add("@CREATIONDATE", MySqlDbType.DateTime);
             command.Parameters["@CREATIONDATE"].Value = staff.creationDate;
             command.ExecuteNonQuery();
             MySqlConnectionManager.CloseConnection(conn);
         }
     }
 }
开发者ID:JSamp701,项目名称:Predator-Check-Management-System,代码行数:29,代码来源:StaffProvider.cs

示例5: mysqlVer

        public static void mysqlVer(MySqlConnection mySqlConnection)
        {
            MySqlCommand mySqlCommand = mySqlConnection.CreateCommand ();
            mySqlCommand.CommandText = "SELECT * FROM categoria";

            MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader ();

            Console.WriteLine ("FieldCount = {0}", mySqlDataReader.FieldCount);
            for (int index = 0; index < mySqlDataReader.FieldCount; index++)
            {
                Console.WriteLine ("Column {0} = {1}", index, mySqlDataReader.GetName (index));

            }

            while (mySqlDataReader.Read())
            {
                object id = mySqlDataReader ["id"];
                object nombre = mySqlDataReader ["nombre"];

                Console.Write ("\n{0}, {1}", id, nombre);

            }

            Console.WriteLine ("\n\nPress any key to continue...");
            Console.Read ();

            mySqlDataReader.Close ();
        }
开发者ID:juankza,项目名称:ad,代码行数:28,代码来源:Program.cs

示例6: GetDBConnection

        public MySqlConnection GetDBConnection()
        {
            try
            {
                MySqlConnection db;
                if (_databaseQueue.Count > 0)
                {
                    db = _databaseQueue.Dequeue();
                    System.Threading.ThreadPool.QueueUserWorkItem(ProcessDatabaseQueue);
                }
                else
                {
                    db = new MySqlConnection(Config.GetConnectionString());
                    db.Open();
                }

                return db;
            }
            catch (MySqlException e)
            {
                MySqlConnection db = new MySqlConnection();
                Logger.WriteLog(e.Message, Logger.LogType.Error);
                db.Dispose();

                return db;
            }
        }
开发者ID:xNexus9,项目名称:tabula-rasa-server-emulator,代码行数:27,代码来源:DatabaseFactory.cs

示例7: GetConnection

        // CONNECTION POOLING IS A MUST!!!
        // TODO: Rewrite needed for config.xml, only providing username, password and database. Create connection string via stringbuilders
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        public static IDbConnection GetConnection()
        {
            IDbConnection conn = null;
            if (Sqltype == "MySql")
            {
                conn = new MySqlConnection(ConnectionString_MySQL);
            }

            if (Sqltype == "MsSql")
            {
                conn = new SqlConnection(ConnectionString_MSSQL);
            }

            if (Sqltype == "PostgreSQL" )
            {
                conn = new NpgsqlConnection(ConnectionString_PostGreSQL);
            }

            if (conn == null)
            {
                throw new Exception("ConnectionString error");
            }

            conn.Open();
            return conn;
        }
开发者ID:Algorithman,项目名称:TestCellAO,代码行数:34,代码来源:Connector.cs

示例8: Dodaj

        protected void Dodaj(object sender, EventArgs e)
        {
            string DruzynaID = txtDruzyna.Text;
            string Imie = txtImie.Text;
            string Nazwisko = txtNazwisko.Text;
            string Data = txtData.Text;
            string Pozycja = txtPozycja.Text;
            string Waga = txtWaga.Text;
            string Wzrost = txtWzrost.Text;
            string Numer = txtNumer.Text;

            string sDate = String.Format("{0:yyyy-mm-dd}", Data);

            MySqlConnection polaczenie = new MySqlConnection(url);
            MySqlCommand cmd = new MySqlCommand("INSERT INTO pilkarze (ID_Druzyny, Imie, Nazwisko, Data_urodz, Pozycja, Waga, Wzrost, Nr_Kosz) VALUES (@IdDruzyny, @imie, @nazwisko, @data, @pozycja, @waga, @wzrost, @numer)", polaczenie);
            MySqlDataAdapter sda = new MySqlDataAdapter();
            cmd.Parameters.AddWithValue("@IdDruzyny", DruzynaID);
            cmd.Parameters.AddWithValue("@imie", Imie);
            cmd.Parameters.AddWithValue("@nazwisko", Nazwisko);
            cmd.Parameters.AddWithValue("@data", sDate);
            cmd.Parameters.AddWithValue("@pozycja", Pozycja);
            cmd.Parameters.AddWithValue("@waga", Waga);
            cmd.Parameters.AddWithValue("@wzrost", Wzrost);
            cmd.Parameters.AddWithValue("@numer", Numer);

            polaczenie.Open();
            cmd.ExecuteNonQuery();
            polaczenie.Close();
            this.WypelnijGridView();
        }
开发者ID:danielblokus,项目名称:Aplikacja-internetowa-technologia-ASP.NET,代码行数:30,代码来源:PilkarzeAdmin.aspx.cs

示例9: ConnectDatabase

 private void ConnectDatabase()
 {
     string connStr = "server=" + caspar_database_server_hostname + ";database=" + caspar_database_server_database + ";uid=" +
         caspar_database_server_username + ";password=" + caspar_database_server_password + ";";
     connection = new MySqlConnection(connStr);
     connection.Open();
 }
开发者ID:zhouqilin,项目名称:CasparCGPlayout,代码行数:7,代码来源:Form1.cs

示例10: Main

        //m mayucula en main obligatoriamente.
        public static void Main(string[] args)
        {
            MySqlConnection mysqlconection = new MySqlConnection (
                "Database=dbprueba;Data Source=localhost;User id=root; Password=sistemas");

            mysqlconection.Open ();

            MySqlCommand mysqlcommand = mysqlconection.CreateCommand ();
            mysqlcommand.CommandText = "select * from articulo";
            //				"select a.categoria as articulocategoria, c.nombre as categorianombre, count(*)" +
            //				"from articulo a " +
            //				"left join categoria c on a.categoria= c.id " +
            //				"group by articulocategoria, categorianombre";

            MySqlDataReader mysqldatareader = mysqlcommand.ExecuteReader ();

            //---------------------------------------------------------------
            updateDatabase (mysqlconection);
            showColumnNames (mysqldatareader);
            show (mysqldatareader);

            //---------------------------------------------------------------
            mysqldatareader.Close ();
            mysqlconection.Close ();
        }
开发者ID:DiegoDeBelda,项目名称:AD,代码行数:26,代码来源:Program.cs

示例11: WykonajSelecta

        /// <summary>
        /// Wykonuje iSelecta na bazie, zwraca MySqlDataReader z wynikami
        /// </summary>
        /// <param name="iSelect">string z SELECTEM</param>
        /// <param name="iGetReaderData">Funkcja(MySqlDataReader), ogarniająca dane</param>
        public static void WykonajSelecta(string iSelect, Action<MySqlDataReader> iGetReaderData)
        {
            //MySqlDataReader readerToReturn;

            string MyConnectionString = "Server=localhost;Database=mydb1;Uid=root;";
            MySqlConnection con = new MySqlConnection(MyConnectionString);
            con.Open();

            try
            {
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = iSelect;
                MySqlDataReader reader = cmd.ExecuteReader();

                //Delegata, który ogarnie dane

                iGetReaderData(reader);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            //no i chuj, żeby zamknąć połączenie trzeba tutaj wjebać delegata
            //return readerToReturn;
        }
开发者ID:Wilczek770,项目名称:Przychodnia,代码行数:37,代码来源:TworzenieZapytan.cs

示例12: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                button5.Enabled = true;
                selectedItem = listBox1.SelectedItem.ToString();
                querry = "SELECT * FROM " + listBox1.SelectedItem.ToString();
                connection = new MySqlConnection(connectionString);
                dataAdapter = new MySqlDataAdapter(querry, connectionString);
                dt = new DataTable();
                dataAdapter.Fill(dt);
                if (dataGridView1.DataSource == null)
                {

                    dataGridView1.Rows.Clear();
                    dataGridView1.Columns.Clear();
                }
                dataGridView1.DataSource = dt;
            }
            catch (NullReferenceException ex)
            {
                MessageBox.Show("Please select one of the databases in the list.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:Tarnacop,项目名称:Monthly-Stock-Planning,代码行数:28,代码来源:UserForm.cs

示例13: IsFullPublic

        public static bool IsFullPublic()
        {
            bool isPublic = false;
            bool isFullyPublic = false;

            using (MySqlConnection con = new MySqlConnection(Database.ConnectionString))
            {
                con.Open();

                using (MySqlCommand command = con.CreateCommand())
                {
                    command.Parameters.AddWithValue("@docID", requestID);
                    command.CommandText =
                        "SELECT public,publicPassword FROM documents WHERE docID = @docID";
                    MySqlDataReader r = command.ExecuteReader();
                    while(r.Read())
                    {
                        isPublic = Convert.ToBoolean(r["public"]);
                        if(isPublic && (r["publicPassword"].ToString() == "" || r["publicPassword"].ToString() == "public"))
                        {
                            isFullyPublic = true;
                        }
                    }

                }

            }
            return isFullyPublic;
        }
开发者ID:Greblak,项目名称:LiveDocs,代码行数:29,代码来源:ViewPublicDocument.aspx.cs

示例14: FetchPublicContent

        public static string FetchPublicContent(string password)
        {
            using (MySqlConnection con = new MySqlConnection(Database.ConnectionString))
            {
                con.Open();

                using (MySqlCommand command = con.CreateCommand())
                {
                    command.Parameters.AddWithValue("@docID", requestID);
                    command.Parameters.AddWithValue("@password", password);
                    command.CommandText =
                       "SELECT Revisions.Content from Revisions join Documents on Revisions.docID=Documents.docID where [email protected] and Revisions.revisionID=(Select Max(revisionID) from Revisions where [email protected]) AND publicPassword = @password" ;
                    MySqlDataReader reader = command.ExecuteReader();

                    if(reader.HasRows)
                    {
                        reader.Read();
                        return LiveDocs.livedocs.Editor.ParseMarkup((String)reader[0]);
                    }
                    else
                    {
                        throw new Exception("Password not correct or document does not exist");
                    }

                }

            }
            return null;
        }
开发者ID:Greblak,项目名称:LiveDocs,代码行数:29,代码来源:ViewPublicDocument.aspx.cs

示例15: AdaptadorABM

        private static MySqlDataAdapter AdaptadorABM(MySqlConnection SqlConnection1)
        {
            MySqlCommand SqlInsertCommand1;
            MySqlCommand SqlUpdateCommand1;
            MySqlCommand SqlDeleteCommand1;
            MySqlDataAdapter SqlDataAdapter1 = new MySqlDataAdapter();
            SqlInsertCommand1 = new MySqlCommand("Generos_Insertar", SqlConnection1);
            SqlUpdateCommand1 = new MySqlCommand("Generos_Actualizar", SqlConnection1);
            SqlDeleteCommand1 = new MySqlCommand("Generos_Borrar", SqlConnection1);
            SqlDataAdapter1.DeleteCommand = SqlDeleteCommand1;
            SqlDataAdapter1.InsertCommand = SqlInsertCommand1;
            SqlDataAdapter1.UpdateCommand = SqlUpdateCommand1;

            // IMPLEMENTACIÓN DE LA ORDEN UPDATE
            SqlUpdateCommand1.Parameters.Add("p_id", MySqlDbType.Int32, 3, "IdGeneroGEN");
            SqlUpdateCommand1.Parameters.Add("p_descripcion", MySqlDbType.VarChar, 50, "DescripcionGEN");
            SqlUpdateCommand1.Parameters.Add("p_activoWeb", MySqlDbType.Int32, 1, "ActivoWebGEN");
            SqlUpdateCommand1.CommandType = CommandType.StoredProcedure;

            // IMPLEMENTACIÓN DE LA ORDEN INSERT
            SqlInsertCommand1.Parameters.Add("p_id", MySqlDbType.Int32, 3, "IdGeneroGEN");
            SqlInsertCommand1.Parameters.Add("p_descripcion", MySqlDbType.VarChar, 50, "DescripcionGEN");
            SqlInsertCommand1.Parameters.Add("p_activoWeb", MySqlDbType.Int32, 1, "ActivoWebGEN");
            SqlInsertCommand1.CommandType = CommandType.StoredProcedure;

            // IMPLEMENTACIÓN DE LA ORDEN DELETE
            SqlDeleteCommand1.Parameters.Add("p_id", MySqlDbType.Int32, 3, "IdGeneroGEN");
            SqlDeleteCommand1.CommandType = CommandType.StoredProcedure;
            return SqlDataAdapter1;
        }
开发者ID:BenjaOtero,项目名称:trend-gestion-desktop,代码行数:30,代码来源:GenerosDAL.cs


注:本文中的MySql.Data.MySqlClient.MySqlConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。