データベースで SQL クエリを実行するコンソール アプリケーションを作成する必要があります。アプリケーションは、この情報を取得してレポートにコンパイルし、このレポートを PDF にエクスポートしてから、PDF レポートを電子メールで送信する必要があります。(これはすべて自動的に行われる必要があります。Windows スケジューラを使用して、特定の日時にこのアプリケーションを実行します。)
これが私がこれまでに持っているものです:
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 レポートを電子メールで送信します。
前もって感謝します!