C#sqlite参数select语句无法从数据库获取结果

时间:2018-10-05 02:44:52

标签: c# sqlite

using (SQLiteConnection conn = new SQLiteConnection())
{
     conn.ConnectionString = ConfigurationManager.ConnectionStrings["Fundverse"].ConnectionString;

     using (SQLiteCommand cmd = new SQLiteCommand())
     {
         cmd.CommandText = "select campaignname, ID from tblcampaigns where " +
                           "campaignname like '%@campaignname%'";

         cmd.Parameters.AddWithValue("@campaignname", prefix);
         cmd.Connection = conn;

         conn.Open();

         using (SQLiteDataReader sdr = cmd.ExecuteReader())
         {
              while (sdr.Read())
              {
                   customers.Add(string.Format("{0}-{1}", sdr["campaignname"], sdr["ID"]));
              }
         }

         conn.Close();
    }

    return customers.ToArray();
}

我的查询有问题吗?我正在尝试检索Campaignname,但是即使我输入完整的单词,仍然没有结果。我在sqlite数据库中的ID是整数,而campaignname是字符串。

0 个答案:

没有答案