在file.WriteAllLines中键入cast casting mismatch问题

时间:2016-02-02 05:06:51

标签: c# database string-concatenation

场景是从DB读取数据并附加2个字符串并传入file.WriteAllLine方法

我想连接string connecString + dc[j] + "INQ;",因为我已经在list<string>中使用了这些内容,但却收到错误。 和file.WriteAllLines方法只接受字符串数组不接受简单数组。 提前致谢

我的代码

public void ComapnySelection_FromDB(string conncString) {

  try {

    Console.WriteLine("-------------------- -------------------- ");

    String que = "select ConsumerNo from " + conncString + "";
    List < string > dc = ConnectToData(que);
    Console.WriteLine("ConsumerNo in DB: " + dc[0]);
    for (int j = 0; j < dc.Count; j++) {
      List<string> combine = conncString + dc[j] + "INQ;";
      Console.WriteLine("Module Name from DB: " + dc[j]);
      File.WriteAllLines(path, dc);

    }
  } catch (Exception) {
    Console.WriteLine("ERROR!");

  }

}

1 个答案:

答案 0 :(得分:0)

也许File.WriteAllText

for (int j = 0; j < dc.Count; j++) {
  var combine = conncString + dc[j] + "INQ;";
  Console.WriteLine("Module Name from DB: " + dc[j]);
  File.WriteAllText(path, combine);

}