469,610 Members | 1,862 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

Help! Why my code can not write string to MDB ?

i need your help, my code as below :
//-----------------------------------------------------------------------
//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 LogInfo4
{
public static void Main(String[] args)
{

string log="System";
string machine="MyDC001";
EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine;

Console.WriteLine("There are {0} entr[y|ies] in the log:",
aLog.Entries.Count);
//get string for print Message
foreach (EventLogEntry entry in aLog.Entries)
{

string strText = entry.Message;
string PrintDocNum,
PrintDocName,PrintUser,PrintServerName,PrintByte,P rintIp,PrintPages;
string strMatch = @"^Document (\d+), *(.+) owned by (.+) was printed on
(.*) via port IP_(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\. Size in bytes:
(\d+); pages printed: (\d+)";
Regex re = new Regex(strMatch);
Match m = re.Match(strText);
if(m.Success)
{
PrintDocNum = m.Groups[1].ToString();
PrintDocName = m.Groups[2].ToString();
PrintUser = m.Groups[3].ToString();
PrintServerName = m.Groups[4].ToString();
PrintIp = m.Groups[5].ToString();
PrintByte = m.Groups[6].ToString();
PrintPages = m.Groups[7].ToString();
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= E:\April30\Db\TestDb.mdb" ;
conn.Open();
string sqlInsert=@"insert into
TestTable(DocNum,DocName,User,ServerName,Byte,Ip,P ages) values
(@PrintDocNum,@PrintDocName,@PrintUser,@PrintServe rName,@PrintByte,@PrintIp,@PrintPages)";
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn);
cmd1.Parameters.Add("@PrintDocNum",System.Data.Ole Db.OleDbType.VarChar,50,PrintDocNum);

cmd1.Parameters.Add("@PrintDocName",System.Data.Ol eDb.OleDbType.VarChar,50,PrintDocName);
cmd1.Parameters.Add("@PrintUser",System.Data.OleDb .OleDbType.VarChar,50,PrintUser);
cmd1.Parameters.Add("@PrintServerName",System.Data .OleDb.OleDbType.VarChar,50,PrintServerName);
cmd1.Parameters.Add("@PrintByte",System.Data.OleDb .OleDbType.VarChar,50,PrintByte);
cmd1.Parameters.Add("@PrintIp",System.Data.OleDb.O leDbType.VarChar,50,PrintIp);
cmd1.Parameters.Add("@PrintPages",System.Data.OleD b.OleDbType.VarChar,50,PrintPages);
//Console.WriteLine("Command Created");
cmd1.ExecuteNonQuery();//insert string
//Console.WriteLine("insert end");
conn.Close();
}

}
}
}
Nov 17 '05 #1
2 1288
hi

where r u getting the error?

did you try to insert the same values directly in access?

cheers,

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

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
i need your help, my code as below :
//-----------------------------------------------------------------------
//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 LogInfo4
{
public static void Main(String[] args)
{

string log="System";
string machine="MyDC001";
EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine;

Console.WriteLine("There are {0} entr[y|ies] in the log:",
aLog.Entries.Count);
//get string for print Message
foreach (EventLogEntry entry in aLog.Entries)
{

string strText = entry.Message;
string PrintDocNum,
PrintDocName,PrintUser,PrintServerName,PrintByte,P rintIp,PrintPages;
string strMatch = @"^Document (\d+), *(.+) owned by (.+) was printed on
(.*) via port IP_(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\. Size in bytes:
(\d+); pages printed: (\d+)";
Regex re = new Regex(strMatch);
Match m = re.Match(strText);
if(m.Success)
{
PrintDocNum = m.Groups[1].ToString();
PrintDocName = m.Groups[2].ToString();
PrintUser = m.Groups[3].ToString();
PrintServerName = m.Groups[4].ToString();
PrintIp = m.Groups[5].ToString();
PrintByte = m.Groups[6].ToString();
PrintPages = m.Groups[7].ToString();
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= E:\April30\Db\TestDb.mdb" ;
conn.Open();
string sqlInsert=@"insert into
TestTable(DocNum,DocName,User,ServerName,Byte,Ip,P ages) values
(@PrintDocNum,@PrintDocName,@PrintUser,@PrintServe rName,@PrintByte,@PrintIp,@PrintPages)";
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn);
cmd1.Parameters.Add("@PrintDocNum",System.Data.Ole Db.OleDbType.VarChar,50,PrintDocNum);

cmd1.Parameters.Add("@PrintDocName",System.Data.Ol eDb.OleDbType.VarChar,50,PrintDocName);
cmd1.Parameters.Add("@PrintUser",System.Data.OleDb .OleDbType.VarChar,50,PrintUser);
cmd1.Parameters.Add("@PrintServerName",System.Data .OleDb.OleDbType.VarChar,50,PrintServerName);
cmd1.Parameters.Add("@PrintByte",System.Data.OleDb .OleDbType.VarChar,50,PrintByte);
cmd1.Parameters.Add("@PrintIp",System.Data.OleDb.O leDbType.VarChar,50,PrintIp);
cmd1.Parameters.Add("@PrintPages",System.Data.OleD b.OleDbType.VarChar,50,PrintPages);
//Console.WriteLine("Command Created");
cmd1.ExecuteNonQuery();//insert string
//Console.WriteLine("insert end");
conn.Close();
}

}
}
}

Nov 17 '05 #2
Hi,Ignacio, it 's end at "send error to Microsoft or not" pop menu, i can
insert the same
values to Mdb manually.and i am beginner in C#,Would please take a carefully
check
at my code?

"Ignacio Machin ( .NET/ C# MVP )" wrote:
hi

where r u getting the error?

did you try to insert the same values directly in access?

cheers,

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

"roopeman" <ro******@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
i need your help, my code as below :
//-----------------------------------------------------------------------
//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 LogInfo4
{
public static void Main(String[] args)
{

string log="System";
string machine="MyDC001";
EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = machine;

Console.WriteLine("There are {0} entr[y|ies] in the log:",
aLog.Entries.Count);
//get string for print Message
foreach (EventLogEntry entry in aLog.Entries)
{

string strText = entry.Message;
string PrintDocNum,
PrintDocName,PrintUser,PrintServerName,PrintByte,P rintIp,PrintPages;
string strMatch = @"^Document (\d+), *(.+) owned by (.+) was printed on
(.*) via port IP_(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\. Size in bytes:
(\d+); pages printed: (\d+)";
Regex re = new Regex(strMatch);
Match m = re.Match(strText);
if(m.Success)
{
PrintDocNum = m.Groups[1].ToString();
PrintDocName = m.Groups[2].ToString();
PrintUser = m.Groups[3].ToString();
PrintServerName = m.Groups[4].ToString();
PrintIp = m.Groups[5].ToString();
PrintByte = m.Groups[6].ToString();
PrintPages = m.Groups[7].ToString();
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= E:\April30\Db\TestDb.mdb" ;
conn.Open();
string sqlInsert=@"insert into
TestTable(DocNum,DocName,User,ServerName,Byte,Ip,P ages) values
(@PrintDocNum,@PrintDocName,@PrintUser,@PrintServe rName,@PrintByte,@PrintIp,@PrintPages)";
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn);
cmd1.Parameters.Add("@PrintDocNum",System.Data.Ole Db.OleDbType.VarChar,50,PrintDocNum);

cmd1.Parameters.Add("@PrintDocName",System.Data.Ol eDb.OleDbType.VarChar,50,PrintDocName);
cmd1.Parameters.Add("@PrintUser",System.Data.OleDb .OleDbType.VarChar,50,PrintUser);
cmd1.Parameters.Add("@PrintServerName",System.Data .OleDb.OleDbType.VarChar,50,PrintServerName);
cmd1.Parameters.Add("@PrintByte",System.Data.OleDb .OleDbType.VarChar,50,PrintByte);
cmd1.Parameters.Add("@PrintIp",System.Data.OleDb.O leDbType.VarChar,50,PrintIp);
cmd1.Parameters.Add("@PrintPages",System.Data.OleD b.OleDbType.VarChar,50,PrintPages);
//Console.WriteLine("Command Created");
cmd1.ExecuteNonQuery();//insert string
//Console.WriteLine("insert end");
conn.Close();
}

}
}
}


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tom | last post: by
reply views Thread by python-help-bounces | last post: by
4 posts views Thread by Sarir Khamsi | last post: by
6 posts views Thread by d.warnermurray | last post: by
2 posts views Thread by BT Openworld | last post: by
9 posts views Thread by JJ | last post: by
8 posts views Thread by Mark | last post: by
3 posts views Thread by lord.zoltar | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.