怎么样才能用C#读取mysql数据到前台页面表格里面呀?

2024-11-23 18:43:06
推荐回答(3个)
回答1:

DataSet dataSet = new DataSet();
OracleCommand sqlCommand = new OracleCommand();
if (_sqlConnection.State != ConnectionState.Open)
{
_sqlConnection.Open();
}
sqlCommand.Connection = _sqlConnection;
sqlCommand.CommandText = "select * from "+ tablename;

OracleDataAdapter sqlDataAdapter = new OracleDataAdapter(sqlCommand);
if (tableName == string.Empty)
sqlDataAdapter.Fill(dataSet);
else
sqlDataAdapter.Fill(dataSet, tableName);

DataTable dt=dataSet.Tables[0].Copy();//从数据库中取得
for(int i=0;i{
Response.Wirte("

  • "+dt.Rows[i]["xxx"].ToString()+"
  • ");
    }
    楼上对的

    回答2:

    this.GridView1.DataSource = ds.Tables["User_Table"];
    this.GridView1.DataBind();

    你还没有完全把数据绑定上去!

    回答3:

    DataTable dt=...//从数据库中取得
    for(int i=0;i{
    Response.Wirte("

  • "+dt.Rows[i]["xxx"].ToString()+"
  • ");
    }