• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MySqlDataAdapter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: MySqlConnection

    public int fjöldi_rada()
    {
        MySqlConnection connection;

         string connectionString = "Server=10.0.105.33;Database=Leikur;Uid=first;Pwd=first;";

         connection = new MySqlConnection(connectionString);

         connection.Open();

         string query = @"SELECT * FROM spilari";
         MySqlCommand cmd = new MySqlCommand(query, connection);

         cmd.ExecuteNonQuery();

         MySqlDataReader queryCommandReader = cmd.ExecuteReader();

         DataTable dataTable = new DataTable();
         dataTable.Load(queryCommandReader);

         MySqlDataAdapter adapter = new MySqlDataAdapter();
         DataSet ds = new DataSet();
         adapter.SelectCommand = cmd;
         adapter.Fill(ds, "SQL Temp Table");
         adapter.Dispose();
         cmd.Dispose();

         return ds.Tables[0].Rows.Count;
    }
开发者ID:ellertsmari,项目名称:testrepo2,代码行数:29,代码来源:Form1.cs


示例2: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MySqlConnection myConn = new MySqlConnection();
                myConn.Host = "192.168.69.8";
                myConn.Port = 3306;
                myConn.UserId = "cody";
                myConn.Password = "greenstreetelite";
                myConn.Open();

                MySqlCommand myCommand = new MySqlCommand(" SELECT * FROM registration.regUser ;", myConn);
                MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
                myDataAdapter.SelectCommand = myCommand;
                DataTable dbDataSet = new DataTable();
                myDataAdapter.Fill(dbDataSet);
                BindingSource bSource = new BindingSource();

                bSource.DataSource = dbDataSet;
                dataGridView1.DataSource = bSource;
                myDataAdapter.Update(dbDataSet);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:heidar-ali,项目名称:mysql-connector,代码行数:28,代码来源:Form1.cs


示例3: FunctionsReturnStringAndDecimal

        public void FunctionsReturnStringAndDecimal()
        {
            execSQL("CREATE TABLE bug52187a (a decimal(5,2) not null)");
            execSQL("CREATE TABLE bug52187b (b decimal(5,2) not null)");
            execSQL("insert into bug52187a values (1.25)");
            execSQL("insert into bug52187b values (5.99)");

            CultureInfo curCulture = Thread.CurrentThread.CurrentCulture;
            CultureInfo curUICulture = Thread.CurrentThread.CurrentUICulture;
            CultureInfo c = new CultureInfo("pt-PT");
            Thread.CurrentThread.CurrentCulture = c;
            Thread.CurrentThread.CurrentUICulture = c;

            string connStr = GetConnectionString(true) + ";functions return string=true";
            try
            {
                using (MySqlConnection con = new MySqlConnection(connStr))
                {
                    con.Open();
                    MySqlDataAdapter da = new MySqlDataAdapter(
                        "select *,(select b from bug52187b) as field_b from bug52187a", con);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    Assert.AreEqual(1, dt.Rows.Count);
                    Assert.AreEqual(1.25, dt.Rows[0][0]);
                    Assert.AreEqual(5.99, dt.Rows[0][1]);
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = curCulture;
                Thread.CurrentThread.CurrentUICulture = curUICulture;
            }
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:34,代码来源:CultureTests.cs


示例4: MultiWord

        public void MultiWord()
        {
            try
            {
                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
                MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
                DataTable dt = new DataTable();
                da.Fill(dt);

                DataRow row = dt.NewRow();
                row["id"] = 1;
                row["name"] = "Name";
                row["dt"] = DBNull.Value;
                row["tm"] = DBNull.Value;
                row["multi word"] = 2;
                dt.Rows.Add(row);
                da.Update(dt);
                Assert.AreEqual(1, dt.Rows.Count);
                Assert.AreEqual(2, dt.Rows[0]["multi word"]);

                dt.Rows[0]["multi word"] = 3;
                da.Update(dt);
                cb.Dispose();
                Assert.AreEqual(1, dt.Rows.Count);
                Assert.AreEqual(3, dt.Rows[0]["multi word"]);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
开发者ID:tdhieu,项目名称:openvss,代码行数:31,代码来源:CommandBuilderTests.cs


示例5: BulkLoadColumnOrder

        public void BulkLoadColumnOrder()
        {
            execSQL(@"CREATE TABLE Test (id INT NOT NULL, n1 VARCHAR(250), n2 VARCHAR(250),
                        n3 VARCHAR(250), PRIMARY KEY(id))");

            // first create the external file
            string path = Path.GetTempFileName();
            StreamWriter sw = new StreamWriter(path);
            for (int i = 0; i < 20; i++)
                sw.WriteLine(i + ",col3,col2,col1");
            sw.Flush();
            sw.Close();

            MySqlBulkLoader loader = new MySqlBulkLoader(conn);
            loader.TableName = "Test";
            loader.FileName = path;
            loader.Timeout = 0;
            loader.FieldTerminator = ",";
            loader.LineTerminator = Environment.NewLine;
            loader.Columns.Add("id");
            loader.Columns.Add("n3");
            loader.Columns.Add("n2");
            loader.Columns.Add("n1");
            int count = loader.Load();
            Assert.AreEqual(20, count);

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            Assert.AreEqual(20, dt.Rows.Count);
            Assert.AreEqual("col1", dt.Rows[0][1]);
            Assert.AreEqual("col2", dt.Rows[0][2]);
            Assert.AreEqual("col3", dt.Rows[0][3].ToString().Trim());
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:34,代码来源:BulkLoading.cs


示例6: AutoIncrementColumnsOnInsert

        public void AutoIncrementColumnsOnInsert()
        {
            execSQL("DROP TABLE IF EXISTS Test");
            execSQL("CREATE TABLE Test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, " +
                "name VARCHAR(100), PRIMARY KEY(id))");
            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(da);

            DataTable dt = new DataTable();
            da.Fill(dt);
            dt.Columns[0].AutoIncrement = true;
            Assert.IsTrue(dt.Columns[0].AutoIncrement);
            dt.Columns[0].AutoIncrementSeed = -1;
            dt.Columns[0].AutoIncrementStep = -1;
            DataRow row = dt.NewRow();
            row["name"] = "Test";

            try
            {
                dt.Rows.Add(row);
                da.Update(dt);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            dt.Clear();
            da.Fill(dt);
            Assert.AreEqual(1, dt.Rows.Count);
            Assert.AreEqual(1, dt.Rows[0]["id"]);
            Assert.AreEqual("Test", dt.Rows[0]["name"]);
            cb.Dispose();
        }
开发者ID:rykr,项目名称:connector-net,代码行数:33,代码来源:CommandBuilderTests.cs


示例7: AutoIncrementColumnsOnInsert2

        public void AutoIncrementColumnsOnInsert2()
        {
            execSQL("CREATE TABLE Test (id INT UNSIGNED NOT NULL " +
                "AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20))");
            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(da);

            MySqlCommand cmd = (MySqlCommand)(cb.GetInsertCommand() as ICloneable).Clone();
            cmd.CommandText += "; SELECT last_insert_id() as id";
            cmd.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
            da.InsertCommand = cmd;

            DataTable dt = new DataTable();
            da.Fill(dt);
            dt.Rows.Clear();

            DataRow row = dt.NewRow();
            row["name"] = "Test";
            dt.Rows.Add(row);
            da.Update(dt);
            Assert.AreEqual(1, dt.Rows[0]["id"]);
            Assert.AreEqual("Test", dt.Rows[0]["name"]);

            row = dt.NewRow();
            row["name"] = "Test2";
            dt.Rows.Add(row);
            da.Update(dt);
            Assert.AreEqual(2, dt.Rows[1]["id"]);
            Assert.AreEqual("Test2", dt.Rows[1]["name"]);

            Assert.AreEqual(1, dt.Rows[0]["id"]);
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:32,代码来源:CommandBuilderTests.cs


示例8: AutoIncrementColumnsOnInsert

        public void AutoIncrementColumnsOnInsert()
        {
            execSQL("CREATE TABLE Test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, " +
                "name VARCHAR(100), PRIMARY KEY(id))");
            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(da);

            da.InsertCommand = cb.GetInsertCommand();
            da.InsertCommand.CommandText += "; SELECT last_insert_id()";
            da.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;

            DataTable dt = new DataTable();
            da.Fill(dt);
            dt.Columns[0].AutoIncrement = true;
            Assert.IsTrue(dt.Columns[0].AutoIncrement);
            dt.Columns[0].AutoIncrementSeed = -1;
            dt.Columns[0].AutoIncrementStep = -1;
            DataRow row = dt.NewRow();
            row["name"] = "Test";

            dt.Rows.Add(row);
            da.Update(dt);

            dt.Clear();
            da.Fill(dt);
            Assert.AreEqual(1, dt.Rows.Count);
            Assert.AreEqual(1, dt.Rows[0]["id"]);
            Assert.AreEqual("Test", dt.Rows[0]["name"]);
            cb.Dispose();
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:30,代码来源:CommandBuilderTests.cs


示例9: Bug19481

        public void Bug19481()
        {
            execSQL("DROP TABLE Test");
            execSQL("CREATE TABLE Test(ID INT NOT NULL AUTO_INCREMENT, " +
                "SATELLITEID VARCHAR(3) NOT NULL, ANTENNAID INT, AOS_TIMESTAMP DATETIME NOT NULL, " +
                "TEL_TIMESTAMP DATETIME, LOS_TIMESTAMP DATETIME, PRIMARY KEY (ID))");
            execSQL("INSERT INTO Test VALUES (NULL,'224','0','2005-07-24 00:00:00'," +
                "'2005-07-24 00:02:00','2005-07-24 00:22:00')");
            execSQL("INSERT INTO Test VALUES (NULL,'155','24','2005-07-24 03:00:00'," +
                "'2005-07-24 03:02:30','2005-07-24 03:20:00')");
            execSQL("INSERT INTO Test VALUES (NULL,'094','34','2005-07-24 09:00:00'," +
                "'2005-07-24 09:00:30','2005-07-24 09:15:00')");
            execSQL("INSERT INTO Test VALUES (NULL,'224','54','2005-07-24 12:00:00'," +
                "'2005-07-24 12:01:00','2005-07-24 12:33:00')");
            execSQL("INSERT INTO Test VALUES (NULL,'155','25','2005-07-24 15:00:00'," +
                "'2005-07-24 15:02:00','2005-07-24 15:22:00')");
            execSQL("INSERT INTO Test VALUES (NULL,'094','0','2005-07-24 17:00:00'," +
                "'2005-07-24 17:02:12','2005-07-24 17:20:00')");
            execSQL("INSERT INTO Test VALUES (NULL,'224','24','2005-07-24 19:00:00'," +
                "'2005-07-24 19:02:00','2005-07-24 19:27:00')");
            execSQL("INSERT INTO Test VALUES (NULL,'155','34','2005-07-24 21:00:00'," +
                "'2005-07-24 21:02:33','2005-07-24 21:22:55')");
            execSQL("INSERT INTO Test VALUES (NULL,'094','55','2005-07-24 23:00:00'," +
                "'2005-07-24 23:00:45','2005-07-24 23:22:23')");

            DateTime date = DateTime.Parse("7/24/2005");
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(CultureInfo.InvariantCulture,
                @"SELECT ID, ANTENNAID, TEL_TIMESTAMP, LOS_TIMESTAMP FROM Test
                WHERE TEL_TIMESTAMP >= '{0}'", date.ToString("u"));
            MySqlDataAdapter da = new MySqlDataAdapter(sql.ToString(), conn);
            DataSet dataSet = new DataSet();
            da.Fill(dataSet);
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:34,代码来源:DateTimeTests.cs


示例10: MultiWord

    public void MultiWord()
    {
      execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(100), dt DATETIME, tm TIME,  `multi word` int, PRIMARY KEY(id))");

      MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
      MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
      DataTable dt = new DataTable();
      da.Fill(dt);

      DataRow row = dt.NewRow();
      row["id"] = 1;
      row["name"] = "Name";
      row["dt"] = DBNull.Value;
      row["tm"] = DBNull.Value;
      row["multi word"] = 2;
      dt.Rows.Add(row);
      da.Update(dt);
      Assert.AreEqual(1, dt.Rows.Count);
      Assert.AreEqual(2, dt.Rows[0]["multi word"]);

      dt.Rows[0]["multi word"] = 3;
      da.Update(dt);
      cb.Dispose();
      Assert.AreEqual(1, dt.Rows.Count);
      Assert.AreEqual(3, dt.Rows[0]["multi word"]);
    }
开发者ID:jimmy00784,项目名称:mysql-connector-net,代码行数:26,代码来源:CommandBuilderTests.cs


示例11: ShowCreateTable

		public void ShowCreateTable()
		{
			MySqlDataAdapter da = new MySqlDataAdapter("SHOW CREATE TABLE Test", conn);
			DataTable dt = new DataTable();
			da.Fill(dt);

			Assert.AreEqual(1, dt.Rows.Count);
			Assert.AreEqual(2, dt.Columns.Count);
		}
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:9,代码来源:Syntax.cs


示例12: ShowCreateTable

    public void ShowCreateTable()
    {
      execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
      MySqlDataAdapter da = new MySqlDataAdapter("SHOW CREATE TABLE Test", conn);
      DataTable dt = new DataTable();
      da.Fill(dt);

      Assert.AreEqual(1, dt.Rows.Count);
      Assert.AreEqual(2, dt.Columns.Count);
    }
开发者ID:jimmy00784,项目名称:mysql-connector-net,代码行数:10,代码来源:Syntax.cs


示例13: fill

 internal static void fill(string queryString, DataTable toReturn)
 {
     using (var conn = new MySqlConnection(connString)) {
         conn.Open();
         conn.ChangeDatabase(Server.MySQLDatabaseName);
         using (MySqlDataAdapter da = new MySqlDataAdapter(queryString, conn)) {
             da.Fill(toReturn);
         }
         conn.Close();
     }
 }
开发者ID:727021,项目名称:MCForge-MCLawl,代码行数:11,代码来源:MySQL.cs


示例14: CommentsInSQL

        public void CommentsInSQL()
        {
            string sql = "INSERT INTO Test /* my table */ VALUES (1 /* this is the id */, 'Test' );" +
                "/* These next inserts are just for testing \r\n" +
                "   comments */\r\n" +
                "INSERT INTO \r\n" +
                "  # This table is bogus\r\n" +
                "Test VALUES (2, 'Test2')";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.ExecuteNonQuery();

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
            DataTable table = new DataTable();
            da.Fill(table);
            Assert.AreEqual(1, table.Rows[0]["id"]);
            Assert.AreEqual("Test", table.Rows[0]["name"]);
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(2, table.Rows[1]["id"]);
            Assert.AreEqual("Test2", table.Rows[1]["name"]);
        }
开发者ID:tdhieu,项目名称:openvss,代码行数:20,代码来源:Syntax2.cs


示例15: AdapterConcurrentException

        public void AdapterConcurrentException()
        {
            execSQL(
                "CREATE TABLE T (" +
                "id_auto int(11) NOT NULL AUTO_INCREMENT," +
                "field varchar(50) DEFAULT NULL," +
                "PRIMARY KEY (id_auto))");

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM T", conn);
            da.InsertCommand = conn.CreateCommand();
            da.InsertCommand.CommandText = @"INSERT INTO T(field) VALUES (@p_field);
                                            SELECT * FROM T WHERE [email protected]@IDENTITY";
            da.InsertCommand.Parameters.Add("@p_field", MySqlDbType.VarChar, 50, "field");
            da.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;

            da.DeleteCommand = conn.CreateCommand();
            da.DeleteCommand.CommandText = "DELETE FROM T WHERE [email protected]_auto";
            da.DeleteCommand.Parameters.Add("@id_auto", MySqlDbType.Int32, 4, "id_auto");

            DataSet ds = new DataSet();
            da.Fill(ds, "T");

            DataTable table = ds.Tables["T"];
            DataRow r = table.NewRow();
            r["field"] = "row";
            table.Rows.Add(r);
            da.Update(table);

            Assert.AreEqual(r.RowState, DataRowState.Unchanged);

            table.Rows[0].Delete();

            r = table.NewRow();
            r["field"] = "row2";
            table.Rows.Add(r);

            da.Update(table); // here was concurrencyviolation
            da.Fill(ds);
            Assert.AreEqual(ds.Tables["T"].Rows.Count, 1);
            Assert.AreEqual(ds.Tables["T"].Rows[0]["field"], "row2");
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:41,代码来源:DataAdapterTests.cs


示例16: BulkCopyCTC

        public void BulkCopyCTC(List<EmployeeDet> list)
        {
            DataTable dt =new DataTable();
            dt.Columns.Add(new DataColumn("employee_id",typeof(System.String)));
            dt.Columns.Add(new DataColumn("employee_name",typeof(System.String)));
            dt.Columns.Add(new DataColumn("emp_ctc",typeof(System.Decimal)));

            foreach(EmployeeDet item in list)
            {
            DataRow dr = dt.NewRow();
            dr["employee_id"]= item.GetID();
            dr["employee_name"]= item.GetName();
            dr["emp_ctc"]= item.GetCTC();
            dt.Rows.Add(dr);
            }

            MySqlConnection con =new MySqlConnection(newConnectionUtils().GetConnectionString());
            if(con.State==ConnectionState.Open)
            {
            con.Close();
            }
            con.Open();
            MySqlCommand cmd =new MySqlCommand("SP_InsertCTC", con);
            cmd.CommandType=CommandType.StoredProcedure;

            cmd.UpdatedRowSource=UpdateRowSource.None;

            cmd.Parameters.Add("?e_id",MySqlDbType.String).SourceColumn="employee_id";
            cmd.Parameters.Add("?e_name",MySqlDbType.String).SourceColumn=  "employee_name";
            cmd.Parameters.Add("?emp_ctc",MySqlDbType.Decimal).SourceColumn=  "emp_ctc";

            MySqlDataAdapter da =new MySqlDataAdapter();
            da.InsertCommand= cmd;
            da.UpdateBatchSize=100;
            int records = da.Update(dt);
            con.Close();
        }
开发者ID:vietlethanh,项目名称:oceo,代码行数:37,代码来源:Program.cs


示例17: AutoIncrementColumnsOnInsert2

        public void AutoIncrementColumnsOnInsert2()
        {
            execSQL("DROP TABLE IF EXISTS Test");
            execSQL("CREATE TABLE Test (id INT UNSIGNED NOT NULL " +
                "AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20))");
            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
            cb.ReturnGeneratedIdentifiers = true;

            DataTable dt = new DataTable();
            da.Fill(dt);
            dt.Rows.Clear();

            try
            {
                DataRow row = dt.NewRow();
                row["name"] = "Test";
                dt.Rows.Add(row);
                da.Update(dt);
                Assert.AreEqual(1, dt.Rows[0]["id"]);
                Assert.AreEqual("Test", dt.Rows[0]["name"]);

                row = dt.NewRow();
                row["name"] = "Test2";
                dt.Rows.Add(row);
                da.Update(dt);
                Assert.AreEqual(2, dt.Rows[1]["id"]);
                Assert.AreEqual("Test2", dt.Rows[1]["name"]);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            Assert.AreEqual(1, dt.Rows[0]["id"]);
        }
开发者ID:rykr,项目名称:connector-net,代码行数:36,代码来源:CommandBuilderTests.cs


示例18: AmbiguousColumns

        public void AmbiguousColumns()
        {
            if (Version < new Version(5, 0)) return;

            execSQL("CREATE TABLE t1 (id INT)");
            execSQL("CREATE TABLE t2 (id1 INT, id INT)");
            execSQL(@"CREATE PROCEDURE spTest() BEGIN SELECT * FROM t1;
                        SELECT id FROM t1 JOIN t2 on t1.id=t2.id;
                        SELECT * FROM t2; END");

            MySqlCommand cmd = new MySqlCommand("spTest", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandTimeout = 0;
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            try
            {
                da.Fill(ds);
                Assert.Fail("The above should have thrown an exception");
            }
            catch (Exception)
            {
            }
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:24,代码来源:StoredProcedure.cs


示例19: UsingParametersTwice

    public void UsingParametersTwice()
    {
      if (Version < new Version(4, 1)) return;

      execSQL(@"CREATE TABLE IF NOT EXISTS Test (input TEXT NOT NULL, 
				UNIQUE (input(100)), state INT NOT NULL, score INT NOT NULL)");

      MySqlCommand cmd = new MySqlCommand(@"Insert into Test (input, 
				state, score) VALUES (?input, ?st, ?sc) ON DUPLICATE KEY 
				UPDATE state=state|?st;", conn);
      cmd.Parameters.Add(new MySqlParameter("?input", ""));
      cmd.Parameters.Add(new MySqlParameter("?st", Convert.ToInt32(0)));
      cmd.Parameters.Add(new MySqlParameter("?sc", Convert.ToInt32(0)));
      cmd.Prepare();

      cmd.Parameters["?input"].Value = "test";
      cmd.Parameters["?st"].Value = 1;
      cmd.Parameters["?sc"].Value = 42;
      int result = cmd.ExecuteNonQuery();
      Assert.AreEqual(1, result);

      MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
      DataTable dt = new DataTable();
      da.Fill(dt);
      Assert.AreEqual(1, dt.Rows.Count);
      Assert.AreEqual("test", dt.Rows[0]["input"]);
      Assert.AreEqual(1, dt.Rows[0]["state"]);
      Assert.AreEqual(42, dt.Rows[0]["score"]);
    }
开发者ID:Top-Cat,项目名称:SteamBot,代码行数:29,代码来源:PreparedStatements.cs


示例20: DBAdapter

            public DBAdapter(int cType, object cLink,string Query)
            {
                this.cType = cType;
                this.cLink = cLink;

                switch (cType)
                {
                    case 0:
                        Adapter = new MySqlDataAdapter(Query, (MySqlConnection)cLink);
                        break;
                    case 1:
                        Adapter = new SqlDataAdapter(Query, (SqlConnection)cLink);
                        break;
                    case 2:
                        Adapter = new SQLiteDataAdapter(Query, (SQLiteConnection)cLink);
                        break;
                }
            }
开发者ID:twiontech,项目名称:aspdotnet_website_framework,代码行数:18,代码来源:DBConnector.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MySqlDatabase类代码示例发布时间:2022-05-24
下一篇:
C# MySqlConnection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap