我正在尝试运行以下代码,但发生的错误说您有error near the @tid.
该参数应该采用 NULL 值。
public static DataTable GetChapterArticlesSummary(long ChapterId, long? TopicId)
{
DataTable TableArticles = new DataTable();
try {
using (SqlConnection connection = ConnectionManager.GetConnection())
{
SqlCommand command = new SqlCommand();
command.CommandText = "Select Article_Name, Id, Privacy_Term from Articles where Chapter_Id=@chapterid and Topic_Id is @topicid";
command.Parameters.Add("@chapterid", SqlDbType.BigInt).Value = ChapterId;
if (TopicId != null)
{
command.Parameters.Add("@topicid", SqlDbType.BigInt).Value = TopicId;
}
else
{
command.Parameters.Add("@topicid", SqlDbType.BigInt).Value = DBNull.Value;
}
command.Connection = connection;
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = command;
Adapter.Fill(TableArticles);
}
}
catch (SqlException ex)
{ }
return TableArticles;
}