Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# sqlite c substr调用错误_C#_Sqlite_Substr - Fatal编程技术网

C# sqlite c substr调用错误

C# sqlite c substr调用错误,c#,sqlite,substr,C#,Sqlite,Substr,任务很简单,有一个本地数据库和一个应用程序,它在其中搜索并显示一个包含结果的表。问题在于SQL查询。我在类表中有3列,我只需要在应用程序的表中显示2列,第二列应该有限制的字母数。SQLite SQL manager执行此查询并向我提供正确的数据,但c向我提供了一个错误 private void SearchButtonClick(object sender, RoutedEventArgs e) { base_connection.ConnectionString =

任务很简单,有一个本地数据库和一个应用程序,它在其中搜索并显示一个包含结果的表。问题在于SQL查询。我在类表中有3列,我只需要在应用程序的表中显示2列,第二列应该有限制的字母数。SQLite SQL manager执行此查询并向我提供正确的数据,但c向我提供了一个错误

private void SearchButtonClick(object sender, RoutedEventArgs e)
    {

        base_connection.ConnectionString = "Data Source=New_test_base.db;Version=3;New=False;Compress=True;";
        base_connection.Open();
        sqlite_cmd= base_connection.CreateCommand();
        sqlite_cmd.CommandText = "select Tag, substr(Description, 1, 2) from Classes where Description = 'rty'";// "select * from Classes where Description = '"+ SearchString.Text+"'";

        DbData = sqlite_cmd.ExecuteReader();


        DbData.Read();
            string myreader = DbData["Tag"].ToString()+DbData["Description"].ToString();

            MessageBox.Show(myreader);


    }
一个错误是:索引超出了大量的数组。不确定措辞,我有俄文VS
我正在使用System.Data.SQLite

您可能需要在查询中提供列别名“Description”

private void SearchButtonClick(object sender, RoutedEventArgs e)
{
    base_connection.ConnectionString = "Data Source=New_test_base.db;Version=3;New=False;Compress=True;";
    base_connection.Open();
    sqlite_cmd= base_connection.CreateCommand();
    sqlite_cmd.CommandText = "select Tag, substr(Description, 1, 2) as Description from Classes where Description = 'rty'";// "select * from Classes where Description = '"+ SearchString.Text+"'";

    DbData = sqlite_cmd.ExecuteReader();
    DbData.Read();
    string myreader = DbData["Tag"].ToString()+DbData["Description"].ToString();

    MessageBox.Show(myreader);
}

这将是我的建议,尽管我可能会为别名使用不同的名称,例如DescripPrefix,以避免在需要整个description字段时出现任何问题。根据类的工作方式,按位置而不是名称进行访问,例如DbData[1]或DbData[2],这取决于索引开始的位置。