写数据库时有错误?!
下面的代码老是有, "Parameter @Doc has no default value "错误, 请问要怎么解决?
//-----------------------------------------------------------------------
//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);
try
{
conn.Open();
cmd1.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
}
}
问题点数:0、回复次数:3Top
1 楼singlepine(小山)回复于 2005-05-03 11:32:54 得分 0
string sqlInsert=@"insert into TestTable(Doc) values (@Doc)";
OleDbCommand cmd1=new OleDbCommand(sqlInsert,conn);
OleDbParameter parm1=new OleDbParameter("@Doc",System.Data.OleDb.OleDbType.VarChar,100);
parm1.Value=strText;
Top
2 楼fanweiwei(黑暗凝聚力量,堕落方能自由)回复于 2005-05-03 14:04:38 得分 0
学习Top
3 楼roopeman(少邦主)回复于 2005-05-03 14:50:56 得分 0
To:singlepine,改成你的方法后有新的报错:
No value given for one or more required parameter
Top




