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


C# MySqlCommand.ExecuteNonQuery方法代码示例

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


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

示例1: 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

示例2: 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

示例3: Update

        /// <summary> 
        /// 修改数据 
        /// </summary> 
        /// <param name="entity"></param> 
        /// <returns></returns> 
        public int Update(Policy entity)
        {
            string sql = "UPDATE  tb_policy SET [email protected],[email protected]ubject,[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

示例4: clear

        public int clear(CuentaDTO cuenta)
        {
            int res = 0;

            try {
                connection.Open();

                MySqlCommand myCommand = new MySqlCommand();
                myCommand.Connection = connection;

                myCommand.CommandText = "DELETE FROM correo WHERE cuenta_idcuenta=?idcuenta";
                myCommand.Parameters.Add("?idcuenta", MySqlDbType.Int16).Value = cuenta.IdCuenta;
                myCommand.ExecuteNonQuery();

                myCommand.CommandText = "DELETE FROM origendestino WHERE 1=1";
                myCommand.ExecuteNonQuery();

                myCommand.CommandText = "DELETE FROM adjunto WHERE 1=1";
                myCommand.ExecuteNonQuery();

                connection.Close();

                res = 1;
                return res;
            }
            catch (MySqlException ex) {
                return -1;
            }
        }
开发者ID:ivanebel,项目名称:ClienteCorreo,代码行数:29,代码来源:CorreoSQL.cs

示例5: initialize

 private void initialize()
 {
     string databaseServer = "127.0.0.1";
     string databaseUsername = "root";
     string databasePassword = "";
     string databaseName = "";
     using (MySqlConnection connection = new MySqlConnection(@"server=" + databaseServer + ";username=" + databaseUsername + ";password=" + databasePassword + ";database=" + databaseName))
     {
         connection.Open();
         string query = null;
         using (MySqlCommand command = new MySqlCommand(query, connection))
         {
             query = "CREATE DATABASE IF NOT EXISTS `laptops-terneuzen` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE `laptops-terneuzen`;";
             command.CommandText = query;
             command.ExecuteNonQuery();
             query = "DROP TABLE IF EXISTS `gebruikers`;CREATE TABLE IF NOT EXISTS `gebruikers` (  `id` tinyint(4) NOT NULL AUTO_INCREMENT,  `gebruikersnaam` varchar(20) NOT NULL,  `wachtwoord` varchar(40) NOT NULL,  `rechten` varchar(1) NOT NULL,  PRIMARY KEY (`id`),  UNIQUE KEY `id` (`id`,`gebruikersnaam`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;";
             command.CommandText = query;
             command.ExecuteNonQuery();
             query = "DROP TABLE IF EXISTS `inventarisatie`;CREATE TABLE IF NOT EXISTS `inventarisatie` (`id` tinyint(4) NOT NULL AUTO_INCREMENT,  `merk` varchar(6) NOT NULL,  `serienummer` varchar(6) NOT NULL,  `hnummer` varchar(6) NOT NULL,  `ruimte` varchar(4) NOT NULL, `locatie` varchar(1) NOT NULL,  `status` char(1) NOT NULL,  `inbezitvan` varchar(20) NOT NULL,  `olcnummer` varchar(3) NOT NULL,  `uitgifte` tinyint(1) NOT NULL,  PRIMARY KEY (`id`),  UNIQUE KEY `hnummer` (`hnummer`),  UNIQUE KEY `serienummer` (`serienummer`),  UNIQUE KEY `olcnummer` (`olcnummer`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";
             command.CommandText = query;
             command.ExecuteNonQuery();
             query = "DROP TABLE IF EXISTS `uitgifte`;CREATE TABLE IF NOT EXISTS `uitgifte` (  `id` tinyint(4) NOT NULL AUTO_INCREMENT,  `leerling-nummer` varchar(6) NOT NULL,  `hnummer` varchar(6) NOT NULL,  `olcnummer` char(3) NOT NULL,  `tijd` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,  PRIMARY KEY (`id`),  UNIQUE KEY `id` (`id`,`hnummer`,`olcnummer`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
             command.CommandText = query;
             command.ExecuteNonQuery();
             MessageBox.Show("Datatabases zijn aangemaakt");
         }
     }
 }
开发者ID:BAICA,项目名称:Multi-Laptop-Manager,代码行数:28,代码来源:Setup.cs

示例6: Main

 public static void Main(string[] args)
 {
     string databaseServer = "127.0.0.1";
     string databaseUsername = "root";
     string databasePassword = "";
     string databaseName = "";
     using (MySqlConnection connection = new MySqlConnection(@"server=" + databaseServer + ";username=" + databaseUsername + ";password=" + databasePassword + ";database=" + databaseName))
     {
         connection.Open();
         string query = null;
         using (MySqlCommand command = new MySqlCommand(query, connection))
         {
             query = "CREATE DATABASE IF NOT EXISTS `laptops-terneuzen` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE `laptops-terneuzen`;";
             command.CommandText = query;
             command.ExecuteNonQuery();
             query = "DROP TABLE IF EXISTS `gebruikers`; CREATE TABLE IF NOT EXISTS `gebruikers` (`id` tinyint(4) NOT NULL AUTO_INCREMENT, `gebruikersnaam` tinytext NOT NULL, `wachtwoord` tinytext NOT NULL, `rechten` tinyint(4) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
             command.CommandText = query;
             command.ExecuteNonQuery();
             query = "DROP TABLE IF EXISTS `inventarisatie`; CREATE TABLE IF NOT EXISTS `inventarisatie` (`id` tinyint(4) NOT NULL AUTO_INCREMENT,  `h-nummer` tinytext NOT NULL,  `merk` tinytext NOT NULL,  `serie-nummer` tinytext NOT NULL,  `locatie` tinytext NOT NULL,  `status` tinyint(4) NOT NULL,  `in-bezit-van` tinytext NOT NULL,  `olc-nummer` tinyint(4) NOT NULL,  `uitgifte` tinyint(1) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
             command.CommandText = query;
             command.ExecuteNonQuery();
             query = "DROP TABLE IF EXISTS `uitgifte`; CREATE TABLE IF NOT EXISTS `uitgifte` (`id` tinyint(4) NOT NULL AUTO_INCREMENT, `leerling-nummer` tinyint(4) NOT NULL, `h-nummer` tinytext NOT NULL, `olc-nummer` tinyint(4) NOT NULL, `tijd` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`),  UNIQUE KEY `leerling-nummer` (`leerling-nummer`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
             command.CommandText = query;
             command.ExecuteNonQuery();
             Console.ReadLine();
         }
     }
 }
开发者ID:BAICA,项目名称:Multi-Laptop-Manager,代码行数:28,代码来源:Program.cs

示例7: gravar

 public void gravar()
 {
     if (validacao())
     {
         MySqlConnection con = new MySqlConnection(Config.Conexao);
         string sql = "insert into parcela_receber(id_conta_receber,valor,data_vencimento,desconto,acrescimo,situacao) values(@a,@b,@c,@d,@e,@g)";
         MySqlCommand cmd = new MySqlCommand(sql, con);
         cmd.Parameters.AddWithValue("@a",conta.id_conta_receber);
         cmd.Parameters.AddWithValue("@b", Convert.ToDecimal(txtvalor.Text));
         cmd.Parameters.AddWithValue("@c",txtdata.Value);
         cmd.Parameters.AddWithValue("@d",0);
         cmd.Parameters.AddWithValue("@e", 0);
         cmd.Parameters.AddWithValue("@g","ABERTA");
         con.Open();
         cmd.ExecuteNonQuery();
         cmd.Parameters.Clear();
         string sit = "";
         if (!conta.situacao.Equals("CANCELADA"))
             sit = ", situacao='ABERTA'";
         sql = "update conta_receber set valor_total=valor_total+" + Convert.ToDecimal(txtvalor.Text) + sit + " where id_conta_receber =" + conta.id_conta_receber;
         cmd.CommandText = sql;
         cmd.ExecuteNonQuery();
         form.filtragem();
         MessageBox.Show("Parcela adicionada com sucesso","",MessageBoxButtons.OK,MessageBoxIcon.Information);
         con.Close();
         this.Close();
     }
 }
开发者ID:guislim,项目名称:SACG,代码行数:28,代码来源:FrmCadParcelaReceber.cs

示例8: Main

    static void Main(string[] args)
    {

        for (;;)
        {
            Thread.Sleep(10000);
            const string connectionString = "Server=localhost; Uid=root; Pwd=123;";
            MySqlConnection connection = new MySqlConnection(connectionString);
            connection.Open();
            MySqlCommand command = new MySqlCommand("USE test_db;", connection);
            command.ExecuteNonQuery();
            command.CommandText = "DROP TABLE IF EXISTS `authorization`;";
            command.ExecuteNonQuery();
            command.CommandText = "CREATE TABLE authorization (id INT(4) PRIMARY KEY AUTO_INCREMENT, value TEXT);";
            command.ExecuteNonQuery();
            string textFromFile = File.ReadAllText(@"C:\Login.txt", Encoding.Default);
            command.CommandText = "INSERT INTO authorization(`value`) VALUES (@param)";
            MySqlParameter param = new MySqlParameter("@param", MySqlDbType.Text);
            param.Value = textFromFile;
            command.Parameters.Add(param);
            command.ExecuteNonQuery();
            command.CommandText = "SELECT value FROM authorization WHERE id=1";
            string textFromDb = (string)command.ExecuteScalar();
            Console.WriteLine(textFromDb);
            connection.Close();
            Console.WriteLine("Готово");
            
        }
        
    }
开发者ID:maxx2223,项目名称:dev,代码行数:30,代码来源:Program.cs

示例9: OnLoad

		protected override void OnLoad (EventArgs e)
		{
			base.OnLoad (e);
			MySqlCommand cmd;
			IDataReader r;
			MySqlConnection con = new MySqlConnection ("Server=127.0.0.1;Database=dht;Uid=dht;Pwd=sgv54hnf3ha142s3dfg4ad5sh;");
			con.Open ();
			try {
				string port = Request.QueryString ["port"];
				ushort tmp_i;
				if (port != null && port.Length > 0 && ushort.TryParse (port, out tmp_i)) {
					cmd = new MySqlCommand ("update nodes set lastupdate=CURRENT_TIMESTAMP where [email protected]", con);
					cmd.Parameters.AddWithValue ("@ep", Request.UserHostAddress + " " + port);
					if (cmd.ExecuteNonQuery () <= 0) {
						cmd.CommandText = "insert into nodes(endpoint) values(@ep)";
						cmd.ExecuteNonQuery ();
					}
				}
				cmd = new MySqlCommand ("SELECT id, endpoint FROM nodes WHERE lastupdate>(subtime(CURRENT_TIMESTAMP,'12:00:00')) order by rand() LIMIT 20", con);
				r = cmd.ExecuteReader ();
				while (r.Read ())
					Response.Output.WriteLine (r.GetString (1));
				r.Close ();
				
			} finally {
				con.Close ();
			}
			
		}
开发者ID:yodamaster,项目名称:workspace,代码行数:29,代码来源:default.aspx.cs

示例10: InsertTest

		public void InsertTest()
		{
			try 
			{
				// do the insert
				MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id,name) VALUES(10,'Test')", conn);
				int cnt = cmd.ExecuteNonQuery();
				Assert.AreEqual( 1, cnt, "Insert Count" );

				// make sure we get the right value back out
				cmd.CommandText = "SELECT name FROM Test WHERE id=10";
				string name = (string)cmd.ExecuteScalar();
				Assert.AreEqual( "Test", name, "Insert result" );

				// now do the insert with parameters
				cmd.CommandText = "INSERT INTO Test (id,name) VALUES(?id, ?name)";
				cmd.Parameters.Add( new MySqlParameter("?id", 11));
				cmd.Parameters.Add( new MySqlParameter("?name", "Test2"));
				cnt = cmd.ExecuteNonQuery();
				Assert.AreEqual( 1, cnt, "Insert with Parameters Count" );

				// make sure we get the right value back out
				cmd.Parameters.Clear();
				cmd.CommandText = "SELECT name FROM Test WHERE id=11";
				name = (string)cmd.ExecuteScalar();
				Assert.AreEqual( "Test2", name, "Insert with parameters result" );
			}
			catch (MySqlException ex)
			{
				Assert.Fail( ex.Message );
			}
		}
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:32,代码来源:CommandTests.cs

示例11: desconto

 public void desconto()
 {
     if (validar())
     {
         decimal valor = Convert.ToDecimal(txtvalor.Text);
         string sql = "update parcela_pagar set desconto = desconto+" + valor;
         sql += ",valor=valor-"+valor;
         sql += " where id_parcela_pagar=" + parcela.id_parcela_pagar;
         MySqlConnection con = new MySqlConnection(Config.Conexao);
         MySqlCommand cmd = new MySqlCommand(sql, con);
         con.Open();
         cmd.ExecuteNonQuery();
         if (valor == parcela.valor)
         {
             sql = "update parcela_pagar set situacao='RECEBIDA' where id_parcela_pagar=" + parcela.id_parcela_pagar;
             cmd.CommandText = sql;
             cmd.ExecuteNonQuery();
         }
         sql = "update conta_pagar set valor_total=valor_total-"+valor;
         sql += " where id_conta_pagar="+conta.id_conta_pagar;
         cmd.CommandText = sql;
         cmd.ExecuteNonQuery();
         con.Close();
         form.pesquisa();
         form.verificar_pagamento();
         form.lista_tudo();
         MessageBox.Show("Desconto inserido com sucesso", "Atencao", MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.Close();
     }
 }
开发者ID:guislim,项目名称:SACG,代码行数:30,代码来源:FrmOperacaoParcela.cs

示例12: GetConnection

        public static MySqlConnection GetConnection(string tableName, bool isFirst)
        {
            _tableName = tableName;
            string cs = @"server=localhost;userid=root;password=root;database=lecast";
            MySqlConnection conn = null;

            try
            {
                conn = new MySqlConnection(cs);
                conn.Open();
                if (isFirst)
                {
                    MySqlCommand cmd = new MySqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandText = "drop table if exists " + tableName;
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = "create table " + tableName + "(user VARCHAR(100), sku VARCHAR(20), category VARCHAR(20), query VARCHAR(255),  click_time TIMESTAMP, query_time TIMESTAMP)";

                    cmd.ExecuteNonQuery();
                }
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("Error: {0}", ex.ToString());
            }

            return conn;
        }
开发者ID:jtxhe,项目名称:lecast,代码行数:29,代码来源:DBManager.cs

示例13: InsertTest

		public void InsertTest()
		{
            execSQL("CREATE TABLE Test (id int NOT NULL, name VARCHAR(100))");
            // do the insert
			MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id,name) VALUES(10,'Test')", conn);
			int cnt = cmd.ExecuteNonQuery();
			Assert.AreEqual( 1, cnt, "Insert Count" );

			// make sure we get the right value back out
			cmd.CommandText = "SELECT name FROM Test WHERE id=10";
			string name = (string)cmd.ExecuteScalar();
			Assert.AreEqual( "Test", name, "Insert result" );

			// now do the insert with parameters
			cmd.CommandText = "INSERT INTO Test (id,name) VALUES(?id, ?name)";
			cmd.Parameters.Add( new MySqlParameter("?id", 11));
			cmd.Parameters.Add( new MySqlParameter("?name", "Test2"));
			cnt = cmd.ExecuteNonQuery();
			Assert.AreEqual( 1, cnt, "Insert with Parameters Count" );

			// make sure we get the right value back out
			cmd.Parameters.Clear();
			cmd.CommandText = "SELECT name FROM Test WHERE id=11";
			name = (string)cmd.ExecuteScalar();
			Assert.AreEqual( "Test2", name, "Insert with parameters result" );
		}
开发者ID:elevate,项目名称:mysqlconnector-.net,代码行数:26,代码来源:CommandTests.cs

示例14: InsertBinary

    public void InsertBinary()
    {
      int lenIn = 400000;
      byte[] dataIn = Utils.CreateBlob(lenIn);

      st.execSQL("DROP TABLE IF EXISTS Test");
      st.execSQL("CREATE TABLE Test (id INT NOT NULL, blob1 LONGBLOB, PRIMARY KEY(id))");

      MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (?id, ?b1)", st.conn);
      cmd.Parameters.Add(new MySqlParameter("?id", 1));
      cmd.Parameters.Add(new MySqlParameter("?b1", dataIn));
      int rows = cmd.ExecuteNonQuery();

      byte[] dataIn2 = Utils.CreateBlob(lenIn);
      cmd.Parameters[0].Value = 2;
      cmd.Parameters[1].Value = dataIn2;
      rows += cmd.ExecuteNonQuery();

      Assert.True(rows == 2, "Checking insert rowcount");

      cmd.CommandText = "SELECT * FROM Test";
      using (MySqlDataReader reader = cmd.ExecuteReader())
      {
        Assert.True(reader.HasRows == true, "Checking HasRows");

        reader.Read();

        byte[] dataOut = new byte[lenIn];
        long lenOut = reader.GetBytes(1, 0, dataOut, 0, lenIn);

        Assert.True(lenIn == lenOut, "Checking length of binary data (row 1)");

        // now see if the buffer is intact
        for (int x = 0; x < dataIn.Length; x++)
          Assert.True(dataIn[x] == dataOut[x], "Checking first binary array at " + x);

        // now we test chunking
        int pos = 0;
        int lenToRead = dataIn.Length;
        while (lenToRead > 0)
        {
          int size = Math.Min(lenToRead, 1024);
          int read = (int)reader.GetBytes(1, pos, dataOut, pos, size);
          lenToRead -= read;
          pos += read;
        }
        // now see if the buffer is intact
        for (int x = 0; x < dataIn.Length; x++)
          Assert.True(dataIn[x] == dataOut[x], "Checking first binary array at " + x);

        reader.Read();
        lenOut = reader.GetBytes(1, 0, dataOut, 0, lenIn);
        Assert.True(lenIn == lenOut, "Checking length of binary data (row 2)");

        // now see if the buffer is intact
        for (int x = 0; x < dataIn2.Length; x++)
          Assert.True(dataIn2[x] == dataOut[x], "Checking second binary array at " + x);
      }
    }
开发者ID:Nicholi,项目名称:mysql-connector-net,代码行数:59,代码来源:BlobTests.cs

示例15: TestMultiPacket

		public void TestMultiPacket()
		{
			int len = 20000000;

            // currently do not test this with compression
            if (conn.UseCompression) return;

            using (MySqlConnection c = new MySqlConnection(GetConnectionString(true)))
            {
                c.Open();
                byte[] dataIn = Utils.CreateBlob(len);
                byte[] dataIn2 = Utils.CreateBlob(len);

                MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (?id, NULL, ?blob, NULL )", c);
                cmd.CommandTimeout = 0;
                cmd.Parameters.Add(new MySqlParameter("?id", 1));
                cmd.Parameters.Add(new MySqlParameter("?blob", dataIn));
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.Message);
                }

                cmd.Parameters[0].Value = 2;
                cmd.Parameters[1].Value = dataIn2;
                cmd.ExecuteNonQuery();

                cmd.CommandText = "SELECT * FROM Test";

                try
                {
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        byte[] dataOut = new byte[len];
                        long count = reader.GetBytes(2, 0, dataOut, 0, len);
                        Assert.AreEqual(len, count);

                        for (int i = 0; i < len; i++)
                            Assert.AreEqual(dataIn[i], dataOut[i]);

                        reader.Read();
                        count = reader.GetBytes(2, 0, dataOut, 0, len);
                        Assert.AreEqual(len, count);

                        for (int i = 0; i < len; i++)
                            Assert.AreEqual(dataIn2[i], dataOut[i]);
                    }
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.Message);
                }
            }
		}
开发者ID:tdhieu,项目名称:openvss,代码行数:58,代码来源:StressTests.cs


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