473,473 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help! i need your kindly help !

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.OleDb Type.VarChar,100,strText);

conn.Open();
try{
cmd1.ExecuteNonQuery();//insert string
}
finally{
conn.Close();
}
}
}
}




Nov 17 '05 #1
5 1325
Hi,

What error are you getting?

why don't you include a catch block and see what the exception is
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
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.OleDb Type.VarChar,100,strText);

conn.Open();
try{
cmd1.ExecuteNonQuery();//insert string
}
finally{
conn.Close();
}
}
}
}



Nov 17 '05 #2
Do you have a folder called test under your c drive? If you don't then you
will get an exception.
Also, like Mr. Machin said, you need to use try catch blocks to see what the
error is. You used try but you didn't catch the exception thrown. Include
the open command in your try block because 95% of the time that's where you
will get errors.

************************************************** ******
DON'T COPY AND PASTE THIS, NOT TESTED
************************************************** ******
try
{
conn.open();
cmd1.ExcecuteNonQuery();
}
catch(Exception ex)
{
Console.writeLine(ex.Message.ToString());
}
finally
{
conn.close();
}
One more thing, why are you opening and closing a connection every time you
are inserting an entry. You can open before your foreach loop. Insert inside
your foreach loop and when you get out of your loop close the connection.

Hope this helps,
--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
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.OleDb Type.VarChar,100,strText);
conn.Open();
try{
cmd1.ExecuteNonQuery();//insert string
}
finally{
conn.Close();
}
}
}
}



Nov 17 '05 #3
Landi,after i add the catch block, got the "Parameter @Doc has no default
value" error.

"Landi" wrote:
Do you have a folder called test under your c drive? If you don't then you
will get an exception.
Also, like Mr. Machin said, you need to use try catch blocks to see what the
error is. You used try but you didn't catch the exception thrown. Include
the open command in your try block because 95% of the time that's where you
will get errors.

************************************************** ******
DON'T COPY AND PASTE THIS, NOT TESTED
************************************************** ******
try
{
conn.open();
cmd1.ExcecuteNonQuery();
}
catch(Exception ex)
{
Console.writeLine(ex.Message.ToString());
}
finally
{
conn.close();
}
One more thing, why are you opening and closing a connection every time you
are inserting an entry. You can open before your foreach loop. Insert inside
your foreach loop and when you get out of your loop close the connection.

Hope this helps,
--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
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.OleDb Type.VarChar,100,strText);

conn.Open();
try{
cmd1.ExecuteNonQuery();//insert string
}
finally{
conn.Close();
}
}
}
}




Nov 17 '05 #4
Why don't you issue simple insert statements?
string sqlInsert=@"insert into TestTable(Doc) values (@Doc)"; instead of putting @Doc put the value that you want
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn); this stays the same
cmd1.Parameters.Add("@Doc",System.Data.OleDb.OleDb Type.VarChar,100,strText);
remove this line, this should already be defined in your table schema. It
knows what to expect and it gets anything other then a varchar then it will
blow up. I have only used parameters with stored procedures with MS SQL
Server and not Access so I don't even know how this works in this case.
conn.Open(); this stays the same.

then execute against the connection.

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Landi,after i add the catch block, got the "Parameter @Doc has no default
value" error.

"Landi" wrote:
Do you have a folder called test under your c drive? If you don't then you will get an exception.
Also, like Mr. Machin said, you need to use try catch blocks to see what the error is. You used try but you didn't catch the exception thrown. Include the open command in your try block because 95% of the time that's where you will get errors.

************************************************** ******
DON'T COPY AND PASTE THIS, NOT TESTED
************************************************** ******
try
{
conn.open();
cmd1.ExcecuteNonQuery();
}
catch(Exception ex)
{
Console.writeLine(ex.Message.ToString());
}
finally
{
conn.close();
}
One more thing, why are you opening and closing a connection every time you are inserting an entry. You can open before your foreach loop. Insert inside your foreach loop and when you get out of your loop close the connection.
Hope this helps,
--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
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.OleDb Type.VarChar,100,strText);

conn.Open();
try{
cmd1.ExecuteNonQuery();//insert string
}
finally{
conn.Close();
}
}
}
}




Nov 17 '05 #5
thanks Landi&Ignacio, problem solved !

"Landi" wrote:
Why don't you issue simple insert statements?
> string sqlInsert=@"insert into TestTable(Doc) values (@Doc)"; instead of putting @Doc put the value that you want
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn); this stays the same
cmd1.Parameters.Add("@Doc",System.Data.OleDb.OleDb Type.VarChar,100,strText);
remove this line, this should already be defined in your table schema. It
knows what to expect and it gets anything other then a varchar then it will
blow up. I have only used parameters with stored procedures with MS SQL
Server and not Access so I don't even know how this works in this case.
conn.Open(); this stays the same.

then execute against the connection.

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com...
Landi,after i add the catch block, got the "Parameter @Doc has no default
value" error.

"Landi" wrote:
Do you have a folder called test under your c drive? If you don't then

you will get an exception.
Also, like Mr. Machin said, you need to use try catch blocks to see what the error is. You used try but you didn't catch the exception thrown. Include the open command in your try block because 95% of the time that's where you will get errors.

************************************************** ******
DON'T COPY AND PASTE THIS, NOT TESTED
************************************************** ******
try
{
conn.open();
cmd1.ExcecuteNonQuery();
}
catch(Exception ex)
{
Console.writeLine(ex.Message.ToString());
}
finally
{
conn.close();
}
One more thing, why are you opening and closing a connection every time you are inserting an entry. You can open before your foreach loop. Insert inside your foreach loop and when you get out of your loop close the connection.
Hope this helps,
--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
> 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.OleDb Type.VarChar,100,strText); >
> conn.Open();
> try{
> cmd1.ExecuteNonQuery();//insert string
> }
> finally{
> conn.Close();
> }
> }
>
>
> }
> }
>
>
>
>
>
>
>
>
>
>


Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.