我必須編寫一個控制檯應用程序,它可以在數據庫上運行sql查詢。然後,應用程序必須將這些信息編譯成報告,將此報告導出爲PDF格式,然後通過電子郵件發送pdf報告。 (所有這一切都必須自動發生 - 我將使用Windows調度運行的具體日期和時間這個應用程序。)在控制檯應用程序中編譯SQL報告
這是我到目前爲止有:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;
using System.Net.Mail;
namespace SqlQueryReports
{
class Program
{
static void Main(string[] args)
{
SqlConnection dataConnection = new SqlConnection();
try
{
dataConnection.ConnectionString ="Data Source=MY-PC\\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True;Pooling=False";
dataConnection.Open();
SqlCommand dataCommand = new SqlCommand();
dataCommand.Connection = dataConnection;
dataCommand.CommandText = "SELECT Product_id,Product_name,Product_price FROM Product";
Console.WriteLine("About to execute: {0}\n\n", dataCommand.CommandText);
SqlDataReader dataReader = dataCommand.ExecuteReader();
// Compile data into Report
// Export Report to .pdf
// Email .pdf report
dataReader.Close();
Console.WriteLine("DONE");
}
catch(SqlException e)
{
Console.WriteLine(e.Message);
}
finally
{
dataConnection.Close();
}
}
}
}
我只需要知道如何到:
- 使用此信息編譯報告。
- 將此報告導出至pdf
- 通過電子郵件發送pdf報告。
在此先感謝!