c# Sql命令错误

标签 c# .net

foreach (string str in TestWords)
{
  //spam
  SqlCommand cmd6 = new SqlCommand("select count from keys,files,folders where keys.fileid=files.id and keys.kname='" + str + "' and files.spam=1 and folders.id<>" + FolIter + " and files.folderid<>" + FolIter + " and files.id='" + s[0].ToString + "'", cn);
  int i6 = Convert.ToInt16(cmd6.ExecuteScalar());
  double temp = Convert.ToDouble((i6 + 1) / (i7 + i8));
  //non spam

  **error**

  SqlCommand cmd9 = new SqlCommand("select count from keys,files,folders where keys.fileid=files.id and keys.kname='" 
    + str 
    + "' and files.spam=0 and folders.id<>"
    + FolIter
    + " and files.folderid<>" 
    + FolIter 
    + " and files.id='" 
    + s[0].ToString 
    + "'", cn);
  int i9 = Convert.ToInt16(cmd9.ExecuteScalar());
  temp2 = Convert.ToDouble((i9 + 1) / (i7 + i8));
  Sdoc = Convert.ToDouble(Sdoc * temp);
  NsDoc = Convert.ToDouble(NsDoc * temp2);
}

我得到的错误是:运算符“+”不能应用于“字符串”和“方法组”类型的操作数

最佳答案

你必须调用方法:

s[0].ToString()

关于c# Sql命令错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3658438/

相关文章:

c# - 如何在 C# 中停止 ffmpeg 用户屏幕录制

c# - 在 Visual Studio 中为 ANTLR 添加构建操作

.net - 搜索中的重要数据结构

c# - 使用 Mono.Cecil 从 ByReferenceType 获取通用参数

.net - 我可以使用仅面向 .NET 4.6.1 的 ASP.NET Core 吗?

c# - 对运行时实例化的类使用依赖注入(inject)

c# - 从 C# 打开的 Outlook 新邮件窗口似乎有焦点,但我的应用程序仍然有它

java - 编写长测试方法名称来描述测试与在代码文档中使用

c# - 在 asp.net web api 中上传文件之前检查文件扩展名

c# - 如何拆分保留整个单词的字符串?