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


C# MySqlDataAdapter.Fill方法代码示例

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


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

示例1: AutoIncrementColumns

        public void AutoIncrementColumns()
        {
            execSQL("DROP TABLE IF EXISTS Test");
            execSQL("CREATE TABLE Test (id int(10) unsigned NOT NULL auto_increment primary key)");
            execSQL("INSERT INTO Test VALUES(NULL)");

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
            DataSet ds = new DataSet();
            da.Fill(ds);
            Assert.AreEqual(1, ds.Tables[0].Rows[0]["id"]);
            DataRow row = ds.Tables[0].NewRow();
            ds.Tables[0].Rows.Add(row);

            try
            {
                da.Update(ds);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            ds.Clear();
            da.Fill(ds);
            Assert.AreEqual(1, ds.Tables[0].Rows[0]["id"]);
            Assert.AreEqual(2, ds.Tables[0].Rows[1]["id"]);
            cb.Dispose();
        }
开发者ID:rykr,项目名称:connector-net,代码行数:29,代码来源:DataAdapterTests.cs

示例2: affichgrid

        public static DataView affichgrid(DataGridView dgv)
        {
            string ConnectionString = "SERVER=localhost;" + "DATABASE=gestioncommerciale;" + "UID=root;" + "PASSWORD=freedomity;";
            MySqlConnection _Conn = DAL.Connexion.connect();
            _Conn.Open();

            DataTable dt = new DataTable();

            string strSql = "SELECT * FROM client";

            MySqlCommand cmd = new MySqlCommand(strSql, _Conn);

            //OleDbDataAdapter joue le rôle de pont entre DataSet et une source de données pour la récupération et l'enregistrement de données.
            MySqlDataAdapter da = new MySqlDataAdapter(strSql, ConnectionString);

            // un cache en mémoire des données récupérées d'une source de données,
            DataSet ds = new DataSet();

            da.Fill(dt);
            da.Fill(ds, "client");

            dgv.DataSource = dt.DefaultView;

            return (ds.Tables["client"].DefaultView);
        }
开发者ID:judaHa,项目名称:dotNETApplications,代码行数:25,代码来源:DAL_Client.cs

示例3: ExecuteDataSet

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="sql">sql 语句</param>
        /// <param name="tablename">指定DataSet中的表,不指定传null</param>
        /// <param name="parameters">参数</param>
        /// <returns>返回DataSet</returns>
        public static DataSet ExecuteDataSet(string sql, string tablename, params MySqlParameter[] parameters)
        {
            using (MySqlConnection conn = new MySqlConnection(Connection))
            {
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                conn.Open();
                if ((parameters != null) && (parameters.Length > 0))
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddRange(parameters);
                }

                DataSet ds = new DataSet();
                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                if (tablename != null)
                {
                    adapter.Fill(ds, tablename);
                }
                else
                {
                    adapter.Fill(ds);
                }

                return ds;
            }
        }
开发者ID:ibollen,项目名称:website,代码行数:33,代码来源:DbHelper.cs

示例4: DataViewControl

        public void DataViewControl()
        {
            string myConn = "datasource=localhost;port=3306;username='root';password=''";
            string Querry = "select * from aus_work.user;";
            MySqlConnection conn = new MySqlConnection(myConn);
            //MySqlCommand cmddatabase = new MySqlCommand(Querry, conn);
            MySqlDataAdapter dataadap = new MySqlDataAdapter(Querry, conn);
            conn.Close();
            DataTable userdatatablecontol = new DataTable();

            dataadap.Fill(userdatatablecontol);
            dataadap.Fill(userdatatable);
            dataGridView1.DataSource = userdatatablecontol;
        }
开发者ID:Nabiha-Batool,项目名称:Aus_Work,代码行数:14,代码来源:Form2.cs

示例5: process

        public void process(ServiceRequest request, ServiceResponse response)
        {
            List<Category> list = new List<Category>();

            string sqlStr = "select * from category";

            MySqlConnection conn = ConnectionManager.getInstance().getConnection();

            conn.Open();

            MySqlDataAdapter mda = new MySqlDataAdapter(sqlStr, conn);
            DataSet ds = new DataSet();
            mda.Fill(ds,"table1");

            conn.Close();

            int count = ds.Tables["table1"].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                Category c = new Category();
                c.categoryId = (int)ds.Tables["table1"].Rows[i][0];
                c.categoryName = (string)ds.Tables["table1"].Rows[i][1];
                list.Add(c);
            }

            GetCategoryResponse serviceResponse = new GetCategoryResponse();
            serviceResponse.categories = list;
            response.responseObj = serviceResponse;
            response.returnCode = 0;
        }
开发者ID:CtripHackthon,项目名称:TravelOnline,代码行数:30,代码来源:GetCategory.cs

示例6: WypelnijGridView

        private void WypelnijGridView()
        {
            txtDruzyna.Text = "";
            txtImie.Text = "";
            txtNazwisko.Text = "";
            txtData.Text = "";
            txtPozycja.Text = "";
            txtWaga.Text = "";
            txtWzrost.Text = "";
            txtNumer.Text = "";

            string constr = ConfigurationManager.ConnectionStrings["pol"].ConnectionString;
            using (MySqlConnection con = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM pilkarze"))
                {
                    using (MySqlDataAdapter sda = new MySqlDataAdapter())
                    {
                        cmd.Connection = con;
                        sda.SelectCommand = cmd;
                        using (DataTable dt = new DataTable())
                        {
                            sda.Fill(dt);
                            GridView1.DataSource = dt;
                            GridView1.DataBind();
                        }
                    }
                }
            }
        }
开发者ID:danielblokus,项目名称:Aplikacja-internetowa-technologia-ASP.NET,代码行数:30,代码来源:PilkarzeAdmin.aspx.cs

示例7: fillgridDef

        private void fillgridDef()
        {
            id = -1;
            buttonDel.Visible = false;
            buttonEdit.Visible = false;
            buttonIns.Visible = false;
            buttonCancel.Visible = false;
            DBConnect NewcConnection = new DBConnect();
            NewcConnection.dbConnection();
            MySqlCommand querysql = new MySqlCommand("Select * From deficiencias", DBConnect.db);

            try
            {
                MySqlDataAdapter dados = new MySqlDataAdapter();
                dados.SelectCommand = querysql;
                DataTable tabela = new DataTable();
                dados.Fill(tabela);
                BindingSource fonte = new BindingSource();
                fonte.DataSource = tabela;
                dataGridView1.DataSource = fonte;
                this.dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[1].HeaderText = "Deficiencia";
                dados.Update(tabela);
                dataGridView1.AutoResizeColumns();
                dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            DBConnect.db.Close();
            textBoxDef.Clear();
        }
开发者ID:hortopericial,项目名称:horto-c-sharp,代码行数:34,代码来源:Deficiencia.cs

示例8: fill_dg1

        public void fill_dg1()
        {
            try
            {
                _connection.Open();
                _mySqlCommand.CommandText = @"SELECT
                    operators.Id_Operator AS 'ID',
                    operators.Surname AS 'ФИО',
                    operators.LevelMD AS 'Уровень MD',
                    operators.LevelUSD AS 'Уровень USD'
                    FROM
                    operators
                    WHERE operators.active = 1
                ";
                _mySqlCommand.Connection = _connection.MySqlConnection;

                var dataAdapter = new MySqlDataAdapter(_mySqlCommand.CommandText, _connection.MySqlConnection);

                var dset = new DataSet();
                dataAdapter.Fill(dset);

                dg1.ItemsSource = dset.Tables[0].DefaultView;
                _connection.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
开发者ID:Nazgard,项目名称:t2_1stan,代码行数:29,代码来源:BDEditorWindow.xaml.cs

示例9: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (con.State == ConnectionState.Closed) con.Open();
        DataTable dt = new DataTable();

        if (ddlGuestType.Text == "De-Activate")
        {

            cmd = new MySqlCommand("SELECT HotelKey as HotelID,HotelName,ListingType,ShortDescription,HotelImage,HotelOverview,VideoLink,PricePerDay,GoogleMapLocation,EmailID,PhoneNumber,Address,City,State,Country,Website " +
                       " FROM  Hotels Where Status='De-Activate' ", con);
        }
        else if (ddlGuestType.Text == "Activate")
        {

            cmd = new MySqlCommand("SELECT HotelKey as HotelID,HotelName,ListingType,ShortDescription,HotelImage,HotelOverview,VideoLink,PricePerDay,GoogleMapLocation,EmailID,PhoneNumber,Address,City,State,Country,Website " +
                       " FROM  Hotels Where Status='Activate' ", con);

        }
        else
        {

            cmd = new MySqlCommand("SELECT HotelKey as HotelID,HotelName,ListingType,ShortDescription,HotelImage,HotelOverview,VideoLink,PricePerDay,GoogleMapLocation,EmailID,PhoneNumber,Address,City,State,Country,Website " +
                     " FROM  Hotels ", con);

        }

        MySqlDataAdapter da = new MySqlDataAdapter(cmd);

        da.Fill(dt);

        ExportToExcel(dt, "Hotels", ddlGuestType.Text + " Hotel" );
        if (con.State == ConnectionState.Open) con.Close();
    }
开发者ID:jescudero,项目名称:MiamiAndMiami,代码行数:33,代码来源:Hotels.aspx.cs

示例10: Load_Topics

        // display all posted topics under the selected forum
        protected void Load_Topics()
        {
            try
            {
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "SELECT * FROM forum_discussions WHERE forum_name = " + "'" + txtForumName.Text + "'";
                //cmd.CommandText = "SELECT * FROM forum_discussions where surname like " + "'" + txtSearch.Text + "%' and  group_name in ('clients') or firstname like " + "'" + txtSearch.Text + "%' and  group_name in ('clients') or customer_id like " + "'" + txtSearch.Text + "%' and  group_name in ('clients') or group_status like " + "'" + txtSearch.Text + "%' and  group_name in ('clients') or email like " + "'" + txtSearch.Text + "%' and  group_name in ('clients') or institution like " + "'" + txtSearch.Text + "%' and  group_name in ('clients') ";

                adap = new MySqlDataAdapter(cmd);
                ds1 = new DataSet();
                adap.Fill(ds1, "forum");

                grdTopics.DataSource = ds1.Tables[0];
                grdTopics.DataBind();

                lblError.Visible = false;

            }
            catch (Exception err)
            {
                lblError.Visible = true;
                lblError.Text = "Error: " + err.Message;
            }

            con.Close();
        }
开发者ID:bharathnr1,项目名称:OtadForum_Web,代码行数:28,代码来源:Forums.aspx.cs

示例11: Index

        // GET: Test
        public ActionResult Index()
        {
            MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=classicmodels; password=root");
            con.Open();

            MySqlCommand query = new MySqlCommand("SELECT contactFirstName, contactLastName FROM customers", con);
            MySqlDataAdapter adp = new MySqlDataAdapter(query);
            DataSet ds = new DataSet();
            adp.Fill(ds);

            List<String> list = ds.Tables[0].AsEnumerable()
                .Select(r => r.Field<String>("contactFirstName"))
                .ToList();

            ViewBag.List = list;

            //List<String> test = new List<String>();

            //test.Add("een");
            //test.Add("twee");
            //test.Add("drie");
            //ViewBag.List = test;

            return View();
        }
开发者ID:RHeijnen,项目名称:SchoolProjectGraveyard,代码行数:26,代码来源:TestController.cs

示例12: Form4

        public Form4()
        {
            InitializeComponent();

            try
            {
                MySqlConnection con = new MySqlConnection(ruta);
                con.Open();
                string consulta = "select * from pc_escritorio";
                MySqlDataAdapter da = new MySqlDataAdapter(consulta, con);

                //lleno
                DataSet ds = new DataSet();
                da.Fill(ds, "pc_escritorio");

                //datos al datagriew
                dataGridView1.DataSource = ds.Tables[0];
                con.Close();

            }
            catch (Exception ee)
            {
                MessageBox.Show("Se produjo un error debido a : " + ee.ToString());

            }
        }
开发者ID:jofeew,项目名称:CRJR_703,代码行数:26,代码来源:Form4.cs

示例13: filldatagrid

        public void filldatagrid()
        {
            string str = sqlcon;
            MySqlConnection con = new MySqlConnection(str);

            string com = "Select id,name,surname,username,gold,military,political,diplomatic,trade,rev_sum,cost_sum from player where username='" + label2.Text + "'" ;
            MySqlDataAdapter adpt = new MySqlDataAdapter(com, con);
            DataSet myDataSet = new DataSet();
            adpt.Fill(myDataSet, "player");
            DataTable myDataTable = myDataSet.Tables[0];
            //DataRow tempRow = null;

            DataRow tempRow1 = null;

            foreach (DataRow tempRow1_Variable in myDataTable.Rows)
            {
                tempRow1 = tempRow1_Variable;
                label1.Text = Convert.ToString(tempRow1["name"] + " " + tempRow1["surname"]);
            }

            dataGridView1.DataSource = myDataSet;
            dataGridView1.DataMember = "player";
            dataGridView1.Columns[0].HeaderText = "Κωδικός Παίκτη";
            dataGridView1.Columns[1].HeaderText = "Όνομα Παίκτη";
            dataGridView1.Columns[2].HeaderText = "Επώνυμο Παίκτη";
            dataGridView1.Columns[3].HeaderText = "Username";
            dataGridView1.Columns[4].HeaderText = "Χρύσος";
            dataGridView1.Columns[5].HeaderText = "Στρατιωτική Ικανότητα";
            dataGridView1.Columns[6].HeaderText = "Πολιτική Ικανότητα";
            dataGridView1.Columns[7].HeaderText = "Διπλωματική Ικανότητα";
            dataGridView1.Columns[8].HeaderText = "Εμπορική Ικανότητα";
            dataGridView1.Columns[9].HeaderText = "Έσοδα";
            dataGridView1.Columns[10].HeaderText = "Έξοδα";
        }
开发者ID:geo7geg,项目名称:1821,代码行数:34,代码来源:Form9.cs

示例14: FatuSemana_Load

 private void FatuSemana_Load(object sender, EventArgs e)
 {
     this.label4.DataBindings.Clear();
     dataSistema = DateTime.Now.ToShortDateString();
     string data="",sDataF="";
     data = dataSistema;
     DateTime d = Convert.ToDateTime(data);
     sDataF = d.ToString("yyyyMMdd");
     try
     {
         MySqlConnection con = new MySqlConnection("SERVER=localhost;" + " DATABASE=banco_rr_sacoles;" + " UID=root;" + "PASSWORD=12345;");
         MySqlDataAdapter sql = new MySqlDataAdapter("SELECT SUM( total ) AS total FROM faturamento WHERE data BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) and '" + sDataF + "'", con);
         //SELECT DATE_SUB(CURDATE(), INTERVAL 7 DAY);
         DataTable dt = new DataTable();
         sql.Fill(dt);
         BindingSource source = new BindingSource();
         source.DataSource = dt;
         this.label4.DataBindings.Add("Text", source, "total", true);
         string total = label4.Text;
         Decimal tt = Convert.ToDecimal(total);
         String tot = tt.ToString("N", new CultureInfo("pt-BR"));
         tbxFaturamento.Text = ("R$ " + (String.Format("{0:0.00}",tt))).ToString();
         con.Close();
     }
     catch (Exception ex)
     {
         ex.Message.ToString();
         //throw new Exception("Erro de comandos: " + ex.Message);
     }
 }
开发者ID:nbleonardo,项目名称:scvs,代码行数:30,代码来源:FatuSemana.cs

示例15: SimpleJoinWithPredicate

    public void SimpleJoinWithPredicate()
    {
      MySqlDataAdapter da = new MySqlDataAdapter(
          @"SELECT b.id,b.name,a.name as author_name from books b JOIN
                    authors a ON b.author_id=a.id WHERE b.pages > 300", conn);
      DataTable dt = new DataTable();
      da.Fill(dt);

      using (testEntities context = new testEntities())
      {
        var q = from b in context.Books
                join a in context.Authors
                on b.Author.Id equals a.Id
                where b.Pages > 300
                select new
                {
                  bookId = b.Id,
                  bookName = b.Name,
                  authorName = a.Name
                };

        string sql = q.ToTraceString();
        CheckSql(sql, SQLSyntax.SimpleJoinWithPredicate);

        int i = 0;
        foreach (var o in q)
          Assert.AreEqual(dt.Rows[i++][0], o.bookId);
        Assert.AreEqual(dt.Rows.Count, i);
      }
    }
开发者ID:Top-Cat,项目名称:SteamBot,代码行数:30,代码来源:JoinTests.cs


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