C# sqlite c substr调用错误
任务很简单,有一个本地数据库和一个应用程序,它在其中搜索并显示一个包含结果的表。问题在于SQL查询。我在类表中有3列,我只需要在应用程序的表中显示2列,第二列应该有限制的字母数。SQLite SQL manager执行此查询并向我提供正确的数据,但c向我提供了一个错误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 =
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],这取决于索引开始的位置。