gpt4 book ai didi

c# - "Cannot perform ' = ' operation on System.Int32 and System.String"执行搜索时

转载 作者:太空狗 更新时间:2023-10-30 00:07:10 25 4
gpt4 key购买 nike

尝试通过 DataList 进行搜索,参数是电影类型(通过数据库加载,因此没有 switch case)和名称

protected void ButtonFilter_Click(object sender, EventArgs e)
{
string filter = "";
int selectedCount = 0;
for (int i = 0; i < this.CheckBoxListGenres.Items.Count; i++)
if (this.CheckBoxListGenres.Items[i].Selected)
selectedCount++;
if (selectedCount > 0)
{
filter = "GenreID=";
int n = 0; //Used to determine to which genre the loop has arrived
for (int i = 0; i < this.CheckBoxListGenres.Items.Count; i++)
{
if (this.CheckBoxListGenres.Items[i].Selected)
{
if (n > 0 && n < selectedCount)
filter += " AND ";
filter+="'*"+this.CheckBoxListGenres.Items[i].Value.ToString()+"*'";
n++;

}
}

if (this.TextBoxMovieName.Text!="")
filter += " AND MovieName LIKE '*" + this.TextBoxMovieName.Text + "*'";
DataTable dataTable = ((DataSet)Application["DataSetMovies"]).Tables[0];
DataView dataView = new DataView(dataTable);
filter = Convert.ToString(filter);
dataView.RowFilter = filter; //!Getting the error here!
this.DataListMovies.DataSource = dataView;
this.DataListMovies.DataBind();
}
}

试过调试,字符串本身似乎没问题,所以我尝试在过滤器上使用 Convert.ToString(),只是为了确定,但这并不重要。帮忙?

提前致谢

最佳答案

这不是编译时错误这是运行时错误。

嗯,在你的数据库中,你正在应用过滤器的东西是 Int32 类型..

例如,如果你有类似 Num 的东西,它是 Int32 但你做了如下的事情:-

dv.RowFilter = "Num = '7097'" ////This will have error

它会抛出错误,因为它需要:-

dv.RowFilter = "Num = 7097" ////This is correct

因此,在您的情况下,您有 GenreID,它是 Int32,但在您的代码中,您提供了一些针对它的字符串。

关于c# - "Cannot perform ' = ' operation on System.Int32 and System.String"执行搜索时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30638295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com