Wpf中如何在列表框中显示查询结果

9cbw7uwe  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(115)

我想显示的结果到列表框corecct格式我现在triyng,但结果是不真实的,我的代码显示的对象在我的屏幕上的名称。之后我在代码后面加上了“.tostring()”,但结果还是错误的,我真的很在意。

OleDbCommand cmd = new OleDbCommand("SELECT OprUser FROM Register WHERE  OprUser    LIKE'%" +txt_owner.Text.ToString() + "%' GROUP BY OprUser");
                conn.Open();
                lstowner.Items.Remove(txt_owner.Text);
                cmd.Connection = conn;
                cmd.ExecuteNonQueryAsync();
                cmd.CommandType = CommandType.Text;
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataTable rows = new DataTable();
                da.Fill(rows);
                int count = rows.Rows.Count;
                if (count > 0)
                { 
                    lstowner.Items.Clear();
                    lstowner.Items.Add(rows.Rows["OprUser"].ToString());
                }
                conn.Close();

字符串
我希望查询结果以正确的格式显示。

lndjwyie

lndjwyie1#

OleDbCommand cmd = new OleDbCommand("SELECT OprUser FROM Register WHERE  OprUser LIKE '%" + txt_owner.Text.ToString() + "%' GROUP BY OprUser");
                conn.Open();
                lstowner.Items.Remove(txt_owner.Text);
                cmd.Connection = conn;
                cmd.ExecuteNonQueryAsync();
                cmd.CommandType = CommandType.Text;
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataTable rows = new DataTable();
                da.Fill(rows);
                int count = rows.Rows.Count;
                if (count > 0)
                {
                   
                    lstowner.Items.Clear();

                    for (int i = 0; i < count; i++)
                    {
                        lstowner.Items.Add(rows.Rows[i]["OprUser"].ToString());
                    }
                }
                conn.Close();

字符串

相关问题