c# SQLite循环错误

本文关键字:错误 循环 SQLite | 更新日期: 2023-09-27 18:02:08

我是一个objective - c编码员,试图写一个Windows 10应用程序,我已经卡住试图查询现有的数据库,开始我只需要拉列"RM_N"从表"storeNames"从dB"字段名称的所有名称。我想使用字符串查询,因为接下来我将转向更复杂的查询。

我认为我在循环的某个地方出错了,我得到了消息

"附加信息:值不在预期范围内。"

带有指向rmNamePick的箭头。

  private class storeNames
        {
            public string RM_N { get; set; }
        }
        private void loadRMnames()
        {
            string fileName = "fieldnames.sql";
            string _path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, fileName);
            if (_path != null)
            {
                using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), _path))
                {
                    var regionNames = conn.Query<storeNames>(@"SELECT RM_N FROM storeNames;");
                    foreach (var names in regionNames)
                    {
                        if (names == null)
                        {
                            rmNamePick.ItemsSource = @"No Data";
                        }
                        else
                        {
                            rmNamePick.Items.Clear();
                            rmNamePick.ItemsSource = names;
                        }
                    }
                }
            }
        }

c# SQLite循环错误

我终于到了

private void loadRMnames()
        {
            List<string> namesArray = new List<string>();
            string fileName = "fieldnames.sql";
            string _path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, fileName);

                using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), _path))
                {
                    var regionNames = conn.Query<storeNames>(@"SELECT RM_N FROM storeNames;");
                foreach (var names in regionNames)
                {
                    namesArray.Add(names.RM_N);
                }

                rmNamePick.Items.Clear();
                rmNamePick.ItemsSource = namesArray;

            }
            }