gpt4 book ai didi

mysql - 未编译 DataColumn 中的乘积表达式,显示错误为 "Cannot find column [max]."

转载 作者:行者123 更新时间:2023-11-29 03:07:33 26 4
gpt4 key购买 nike

运行代码时出现错误“找不到列 [max]。”但我已将最大和最小列添加到数据集中的表中

MySql.Data.MySqlClient.MySqlConnection mycon = new MySqlConnection(GetConnectionString());
if (mycon.State != ConnectionState.Open)

{

string sqlCat = "SELECT * FROM out_of_mark_table";
string sqlProd = "SELECT * FROM scord_mark_table";

MySqlDataAdapter da = new MySqlDataAdapter(sqlCat, mycon);
DataSet ds = new DataSet();

try
{
mycon.Open();
da.Fill(ds, "out_of_mark_table");

da.SelectCommand.CommandText = sqlProd;
da.Fill(ds, "scord_mark_table");
}
finally
{
mycon.Close();
}

DataRelation relat = new DataRelation("CatProds", ds.Tables["out_of_mark_table"].Columns["test_id"], ds.Tables["scord_mark_table"].Columns["test_id"]);
ds.Relations.Add(relat);

DataColumn count = new DataColumn("Products (#)", typeof(int), "COUNT(Child(CatProds).test_id)");
DataColumn max = new DataColumn("Most Expensive Product", typeof(decimal), "MAX(Child(CatProds).total)");
DataColumn min = new DataColumn("Least Expensive Product", typeof(decimal), "MIN(Child(CatProds).total)");
DataColumn no=new DataColumn("No");
DataColumn IdCol = new DataColumn();
min.Caption = "min";
max.Caption = "max";
string expr = "max * min";

IdCol.ColumnName = "ID";
IdCol.DataType = Type.GetType("System.Int32");
IdCol.ReadOnly = true;
IdCol.AllowDBNull = false;
//IdCol.Unique = true;
IdCol.AutoIncrement = true;
IdCol.AutoIncrementSeed = 1;
IdCol.AutoIncrementStep = 1;



ds.Tables["out_of_mark_table"].Columns.Add(count);
ds.Tables["out_of_mark_table"].Columns.Add(max);
ds.Tables["out_of_mark_table"].Columns.Add(min);
ds.Tables["out_of_mark_table"].Columns.Add(IdCol);
DataColumn sum = new DataColumn("Sum of", typeof(int), expr, MappingType.Attribute);
**ds.Tables["out_of_mark_table"].Columns.Add(sum);**
IdCol.SetOrdinal(0);
GridView1.DataSource = ds.Tables["out_of_mark_table"];
GridView1.DataBind();

最佳答案

您已将标题设置为“Max”和“Min”,但DataColumns 的 标识符是OrdinalColumnName .您已通过 constructor 设置了 ColumnName

“最贵的产品”“最便宜的产品”

所以用

string expr = "[Most Expensive Product] * [Least Expensive Product]";

相反。

关于mysql - 未编译 DataColumn 中的乘积表达式,显示错误为 "Cannot find column [max].",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13130047/

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