쿼리가 실행되는 동안 쿼리를 실행하려고했지만 아무 것도 삽입하지 않았거나 오류를 반환하지 않았습니다.SQL 쿼리가 삽입되지 않습니다.
데이터베이스 연결이 열려 있고 정상적으로 연결되어 있습니다.
public void insertError(string error, DateTime time)
{
SqlCeParameter[] sqlParams = new SqlCeParameter[]
{
new SqlCeParameter("@exception", error),
new SqlCeParameter("@time", time)
};
try
{
cmd = new SqlCeCommand();
cmd.Connection = connection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO errorlog (exception, time) VALUES(@exception, @time)";
cmd.Parameters.AddRange(sqlParams);
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
어떤 도움을 주시면 감사하겠습니다, 감사합니다 사전에 :
이 표는 다음 데이터
- id (int autoincremental, Primary key, Unique)
- exception (varchar)
- time (DateTime)
exception = String(error message)
time = DateTime.Now
오류 로그 전화를 보유하고있다 여기에 코드입니다. 이 호출되는
protected DataController()
{
try
{
string appPath = System.IO.Path.GetDirectoryName(Assembly.GetAssembly(typeof(DataController)).CodeBase).Replace(@"file:\", "") + @"\";
string strCon = @"Data Source = " + appPath + @"Data\EasyShop.sdf";
connection = new SqlCeConnection(strCon);
}
catch (Exception e)
{
}
connection.Open();
}
마지막 방법 :
public bool log(string msg, bool timestamp = true)
{
DataController dc = DataController.Instance();
dc.insertError(msg, DateTime.Today);
return true;
}
time = DateTime, DataType을 nVarChar로 설정하여 ToString()을 사용해 보았습니다. 전혀 차이가 없다. 아무런 오류없이 삽입되지 않습니다. – Deejdd
@exception에서 따옴표를 제거하고 다시 시도하십시오. – vtortola
우선 코드에 대한 리펙터링 ... 전체적인 접근법이 특히 매개 변수를 처리하는 방법에있어 잘못된 것으로 보입니다. – MethodMan