Hier ist mein Code:
Code: Select all
static void Main(string[] args)
{
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\dropDirectory";
// Add event handlers.
watcher.Created += new FileSystemEventHandler(OnChanged);
// Begin watching.
watcher.EnableRaisingEvents = true;
while(DateTime.Now.Hour < 10);
}
private static void OnChanged(object source, FileSystemEventArgs e)
{
string strInsert = "INSERT INTO Files (Filename) VALUES ('" + e.Name + "')";
string strConnection = "Server = server_name; Database = database_name; User Id = user_id; Password = password;";
using (SqlConnection con = new SqlConnection(strConnection))
{
using (SqlCommand cmd = new SqlCommand(strInsert, con))
{
con.Open();
cmd.ExecuteScalar();
}
}
}