我需要开发一个程序,将 a 的结果保存select
在两个变量中,并将数据保存在 txt 中,并在控制台上显示生成的 url 迭代
我能够让它在控制台中正确打印,你能告诉我如何将迭代结果保存在 txt 中,为每一行写入一个带有换行符的 url。
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string url1 = null;
SqlConnection con = new SqlConnection("server=SQL2014;database=ventas;integrated security = true");
string strSQL = "select Numero,Terreno "+
"FROM datos";
SqlCommand cmd = new SqlCommand(strSQL, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string resultadoNumero = reader["Numero"].ToString();
string resultadoTerreno = reader["Terreno"].ToString();
url1 = "http://ReportServer/Pages/ReportViewer.aspx?/Pedidos" + resultadoNumero + resultadoTerreno;
Console.WriteLine(url1);
}
reader.Close();
con.Close();
Console.ReadLine();
}
}
}
您应该考虑以下几点:
在哪里,该变量
builder
将存储所有已构建的 Url,并使用File.WriteAllText
它将创建(如果不存在)文件的方法并写入所有文本。附:不要忘记做必要的参考。
参考: