gpt4 book ai didi

c# - 如何在 C# 中从一个 mysql 表填充两个不同的数据网格

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

我的申请有问题。我想在 C# 中使用 WPF 从一个 mysql 表中填充两个不同的 DataGrid

我不知道如何正确地做到这一点。下面是我的示例代码,它不起作用。它目前只填充 czesciTables,但不填充 czesciTables2

我一直在研究如何做到这一点,但谷歌只向我显示来自其他来源的结果。

try
{
for (int i = 0; i <= 4; i++ )
{
connection.Open();
MySqlCommand cmd = new MySqlCommand("SELECT id_czesci_symbol AS KOD,
ilosc AS ILOSC
FROM `test`.`zamowienie`
WHERE z_numer_naprawy='" + numberBox.Content.ToString() + "'
ORDER BY ilosc LIMIT 5;", connection);
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds, "LoadDataBinding");
czesciTable.DataContext = ds;
}

for (int i = 5; i <= 9; i++)
{
connection.Open();
MySqlCommand cmd2 = new MySqlCommand("SELECT id_czesci_symbol AS KOD,
ilosc AS ILOSC
FROM `test`.`zamowienie`
WHERE z_numer_naprawy='" + numberBox.Content.ToString() + "'
ORDER BY ilosc LIMIT 5;", connection);
MySqlDataAdapter adp2 = new MySqlDataAdapter(cmd2);
DataSet ds2 = new DataSet();
adp2.Fill(ds2, "LoadDataBinding");
czesciTable2.DataContext = ds2;
}
}
catch (MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
connection.Close();
}

最佳答案

为了直接回答您的问题,下面是示例代码。

try
{
for (int i = 0; i <= 9; i++ )
{
connection.Open();
MySqlCommand cmd = new MySqlCommand("SELECT id_czesci_symbol AS KOD,
ilosc AS ILOSC
FROM `test`.`zamowienie`
WHERE z_numer_naprawy='" + numberBox.Content.ToString() + "'
ORDER BY ilosc LIMIT 5;", connection);
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds, "LoadDataBinding");
if (i < 5)
czesciTable.DataContext = ds;
else
czesciTable2.DataContext = ds;

cmd.Dispose();
adp.Dispose();
}
}catch (MySqlException ex) {
MessageBox.Show(ex.ToString());
}finally {
connection.Close();
}

您要存档的是什么?也许我们可以帮助您更好地解决您的问题。

关于c# - 如何在 C# 中从一个 mysql 表填充两个不同的数据网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30847073/

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