G
Guest
i wrote the below code , just want got local machine application Eventlog 's
message , and write to MDB.but it 's can not write the message to Mdb,
somebody can check it for me? thanks!
//-----------------------------------------------------------------------
//Wrote by Michael April 30 2005
//-----------------------------------------------------------------------
using System.Text;
using System.Diagnostics;
using System.Threading;
using System;
using System.Text.RegularExpressions;
using System.Data.OleDb;
public class LogTest
{
public static void Main(String[] args)
{
string log="Application";
string machine=".";
EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine;
Console.WriteLine("There are {0} entr[y|ies] in the log:",
aLog.Entries.Count);
foreach (EventLogEntry entry in aLog.Entries)
{
string strText = entry.Message;
//Console.WriteLine(strText);
OleDbConnection conn = new OleDbConnection();
// TODO: Modify the connection string and include any
// additional required properties for database.
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= c:\test\TestDb2.mdb" ;
string sqlInsert=@"insert into TestTable(Doc) values (@Doc)";
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn);
cmd1.Parameters.Add("@Doc",System.Data.OleDb.OleDbType.VarChar,100,strText);
conn.Open();
try{
cmd1.ExecuteNonQuery();//insert string
}
finally{
conn.Close();
}
}
}
}
message , and write to MDB.but it 's can not write the message to Mdb,
somebody can check it for me? thanks!
//-----------------------------------------------------------------------
//Wrote by Michael April 30 2005
//-----------------------------------------------------------------------
using System.Text;
using System.Diagnostics;
using System.Threading;
using System;
using System.Text.RegularExpressions;
using System.Data.OleDb;
public class LogTest
{
public static void Main(String[] args)
{
string log="Application";
string machine=".";
EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine;
Console.WriteLine("There are {0} entr[y|ies] in the log:",
aLog.Entries.Count);
foreach (EventLogEntry entry in aLog.Entries)
{
string strText = entry.Message;
//Console.WriteLine(strText);
OleDbConnection conn = new OleDbConnection();
// TODO: Modify the connection string and include any
// additional required properties for database.
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= c:\test\TestDb2.mdb" ;
string sqlInsert=@"insert into TestTable(Doc) values (@Doc)";
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn);
cmd1.Parameters.Add("@Doc",System.Data.OleDb.OleDbType.VarChar,100,strText);
conn.Open();
try{
cmd1.ExecuteNonQuery();//insert string
}
finally{
conn.Close();
}
}
}
}