gpt4 book ai didi

c# - 从mysql数据库获取表来填充datalist

转载 作者:行者123 更新时间:2023-11-29 13:11:38 25 4
gpt4 key购买 nike

到目前为止,我确实成功地从数据库中获取了值。我的问题是无法将数据列表中的数据填充为表。我获取简单值的代码如下:

try
{
using (OdbcConnection connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString))
{
connection.Open();
using (OdbcCommand command = new OdbcCommand("SELECT * FROM datas", connection))
using (OdbcDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
switch (dr["namen"].ToString())
{
case "gt": Label2.Text = dr["dest"].ToString(); break;
case "gp1": Image1.ImageUrl = dr["dest"].ToString(); break;
case "gp2": Image2.ImageUrl = dr["dest"].ToString(); break;
case "gp3": Image3.ImageUrl = dr["dest"].ToString(); break;
}
}
dr.Close();
}
connection.Close();
}
}
catch (Exception ex)
{
Response.Write("An error occured: " + ex.Message);
}

最佳答案

使用DataAdapter,填充到数据表

http://www.codeproject.com/Questions/358631/how-to-bind-data-from-sql-server-to-datalist-using

List <string> datalist1 = new List<string>();

datalist1.DataSource = _dtTable1;

datalist1.DataBind();

关于c# - 从mysql数据库获取表来填充datalist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22019866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com