0

MySQL クエリを、select ステートメントが機能しているテーブルでいっぱいの li タグに出力したいのですが、MySQL の世界都市のサンプル DB を使用しているだけです。質問は、個々の行と列にアクセスする最も簡単な方法は何ですか? データをプッシュする新しいクラスまたは構造体を作成する必要がありますか? データテーブルをハッシュテーブルのリストのようなものに変換できるようにしたいですか? JSON.net のようなものを使用する必要がありますか?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using Newtonsoft.Json;

namespace MySQL
{
    public partial class _default : System.Web.UI.Page
    {
        string connStr = "server=localhost;User Id=root;Persist Security Info=True;database=world; Password=root";
        MySqlDataAdapter countries;
        DataSet ds;

        protected void Page_Load(object sender, EventArgs e)
        {

            MySqlConnection conn = new MySqlConnection(connStr);
            string sql = "SELECT * FROM country";
            countries = new MySqlDataAdapter(sql, conn);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(countries);

            ds = new DataSet();
            countries.Fill(ds, "Country");

        }
    }
}

私はjquery、javascript、angularjsに精通しています.html出力については心配していませんが、個々の列にアクセスする最も簡単な方法は何ですか? それらを出力する行?

4

1 に答える 1

1

行と列ですべてのテーブルにアクセスしたいと思います。

これを行う

 MySqlConnection conn = new MySqlConnection(connStr);
      string sql = "SELECT * FROM country";
      countries = new MySqlDataAdapter(sql, conn);
      MySqlCommandBuilder cb = new MySqlCommandBuilder(countries);

      ds = new DataSet();
      countries.Fill(ds, "Country");
      DataTable dt;
      for (int i = 0; i <ds.Tables.Count; i++)//traverse by each table in dataset
      {
           dt = ds.Tables[i];

           for (int j = 0; j < dt.Rows.Count; j++)//traverse by row
           {
                Response.Write("Current Row--> "+j.ToString()+Environment.NewLine);
                object[] ob = dt.Rows[j].ItemArray; // get array of column from present row
                for (int k = 0; k <= ob.GetUpperBound(0); k++)
                {
                     Response.Write("Current column Number--> "+k.ToString()+" Value = "+ob[k].ToString()+Environment.NewLine);
                }
           }

      }
于 2013-10-31T06:13:57.663 に答える