Search Results

Search found 1 results on 1 pages for 'deejdd'.

Page 1/1 | 1 

  • SQL query doesn't get inserted

    - by Deejdd
    I've been trying to get my query to work for some time it runs but doesn't insert anything nor does it return any errors. The database connection is open and is successfuly connection. The Table is called errorlog and holds the following data - id (int autoincremental, Primary key, Unique) - exception (varchar) - time (DateTime) exception = String(error message) time = DateTime.Now Here's the code: 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); } } Any help would be appreciated, Thanks in advance. EDIT Removed quotes around @exception Heres the connection: 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(); } Finally the way it gets called: public bool log(string msg, bool timestamp = true) { DataController dc = DataController.Instance(); dc.insertError(msg, DateTime.Today); return true; }

    Read the article

1