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


C# MySqlDataAdapter.Fill方法代码示例

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


在下文中一共展示了MySqlDataAdapter.Fill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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

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

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

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

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

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

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

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

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


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