[英]Cannot resolve symbol 'parameters' when using SQLCommandBuilder
I'm trying to fetch a query from the database and I've done the following: 我正在尝试从数据库中获取查询,并且已完成以下操作:
public DataTable FetchTasks(string questName, string categoryName)
{
const string queryString = @" SELECT *
FROM dbo.Task as t
INNER JOIN dbo.[Quest] as q
on q.QuestID = t.QuestID
INNER JOIN dbo.[Category] as c
on c.CategoryID = t.CategoryID
WHERE q.[Description] = @questName
AND c.CategoryTitle = @categoryName";
using (var dataAdapter = new SqlDataAdapter(queryString, ConnectionString))
{
using (var cmd = new SqlCommandBuilder(dataAdapter))
{
cmd.Parameters.AddWithValue("@questName", questName);
cmd.Parameters.AddWithValue("@categoryName", categoryName);
var table = new DataTable { Locale = System.Globalization.CultureInfo.InvariantCulture };
dataAdapter.Fill(table);
return table;
}
}
However I'm receiving an error on the following lines: 但是,我在以下几行中收到错误:
cmd.Parameters.AddWithValue("@questName", questName);
cmd.Parameters.AddWithValue("@categoryName", categoryName);
That reads: 内容如下:
Cannot resolve symbol 'Parameters'
无法解析符号“参数”
Where have I gone wrong here? 我在哪里错了? I know the mistake is in where I've added the parameters - but I don't understand enough to know how to correct it.
我知道错误在于我在哪里添加了参数-但是我不了解如何更正它。
The Parameters
collection isn't accessible directly from SqlCommandBuilder
. 无法从
SqlCommandBuilder
直接访问Parameters
集合。
Try replacing the two lines in question with these: 尝试用这些替换有问题的两行:
cmd.DataAdapter.SelectCommand.Parameters.AddWithValue("@questName", questName);
cmd.DataAdapter.SelectCommand.Parameters.AddWithValue("@categoryName", categoryName);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.