希望您能帮助我们检查这个错误。我们正试图用这段代码填充一堆标签,但只是不断地重复出现同样的错误。我已经添加了下面的代码和错误以及。
希望您能给我们提供答案,谢谢!我需要帮助检查如何使用列表来为我们的项目添加标签上的值。
对于每个会回复的人,提前谢谢。
错误:
列表上没有输出或值,无法使用列表更改标签上的值。
private void cboSelectedProdut_SelectedIndexChanged(object sender,
EventArgs e)
{
List<string> conts = new List<string>();
if (cboSelectedProdut.Text != "")
{
PointofSALES sales = new PointofSALES();
conts = sales.CallProduct(cboCategory.Text,
cboSelectedProdut.Text);
lblID.Text = conts[1];
lblPrice.Text = conts[3];
lblStock.Text = conts[4];
}
}
public List<string> CallProduct(string category, string param)
{
string table, product, param1 , param2 , param3;
List<string> stacks = new List<string>();
if (category == "Accessories")
{
product = "Accessories_Name";
table = "tbl_accessories";
param1 = "Accessories_ID";
param2 = "Accessories_Quantity";
param3 = "Accessories_Price";
stacks.AddRange(Catt(product, table, param).ToArray());
}
else if (category == "Batteries")
{
product = "Batteries_Name";
table = "tbl_batteries";
param1 = "Accessories_ID";
param2 = "Accessories_Quantity";
param3 = "Accessories_Price";
//stacks.AddRange(Catt(product, table, param, param1,
param2, param3).ToArray());
}
else if (category == "Cotton")
{
product = "Cotton_Name";
table = "tbl_cotton";
param1 = "Accessories_ID";
param2 = "Accessories_Quantity";
param3 = "Accessories_Price";
//stacks.AddRange(Catt(product, table, param, param1,
param2, param3).ToArray());
}
else if (category == "Juices")
{
product = "Juices_Name";
table = "tbl_juices";
param1 = "Accessories_ID";
param2 = "Accessories_Quantity";
param3 = "Accessories_Price";
//stacks.AddRange(Catt(product, table, param, param1,
param2, param3).ToArray());
}
else if (category == "Kits")
{
product = "Kits_Name";
table = "tbl_kits";
param1 = "Accessories_ID";
param2 = "Accessories_Quantity";
param3 = "Accessories_Price";
//stacks.AddRange(Catt(product, table, param, param1,
param2, param3).ToArray());
}
else if (category == "Mods")
{
product = "Mods_Name";
table = "tbl_mods";
param1 = "Accessories_ID";
param2 = "Accessories_Quantity";
param3 = "Accessories_Price";
//stacks.AddRange(Catt(product, table, param, param1,
param2, param3).ToArray());
}
else
{
product = "VapeSet_Name";
table = "tbl_vapeset";
param1 = "Accessories_ID";
param2 = "Accessories_Quantity";
param3 = "Accessories_Price";
//stacks.AddRange(Catt(product, table, param, param1,
param2, param3).ToArray());
}
return stacks;
}
public List<string> Catt(string product, string table, string
param)
{
string id, quantity, price;
List<string> Products = new List<string>();
Global global = new Global();
string sql = "SELECT * FROM " + table + " WHERE @pram LIKE
@param ";
MySqlConnection connection = new
MySqlConnection(global.ConnectionString);
MySqlCommand command = new MySqlCommand(sql, connection);
command.Parameters.AddWithValue("@param", param);
command.Parameters.AddWithValue("@pram", product);
connection.Open();
MySqlDataReader reader = command.ExecuteReader();
{
while (reader.Read())
{
for (int x = 0; x < reader.FieldCount; x++)
{
Products.Add(Convert.ToString(reader.GetValue(x)));
}
}
}
return Products;
}
2条答案
按热度按时间ioekq8ef1#
不能在sql语句中使用参数作为列名,因为它们将被编码为字符串(这会导致sql语法错误)。就像
table
,使用字符串连接插入这些值(此外,表名和WHERE
.)5q4ezhmt2#
这似乎是一个拼写错误,你需要添加一个空格之前
WHERE
改变至