I'm working on Visual Studio 2012 using an MS Access file as Database and having a bunch of trouble with this insert:
cmd.Parameters.Add(new OleDbParameter("@codigo", cal.CodEtiq)); // Value = int
cmd.Parameters.Add(new OleDbParameter("@data", cal.Data.ToString("yyyy-MM-dd hh:mm"))); //Value = 2013-10-29 00:00
cmd.Parameters.Add(new OleDbParameter("@entidade", cal.EntidadeCal)); // Value = string
cmd.Parameters.Add(new OleDbParameter("@observacao", cal.Observacao)); // Value = string
cmd.Parameters.Add(new OleDbParameter("@certificado", cal.Certificado)); // Value = string
cmd.Parameters.Add(new OleDbParameter("@resultado", cal.Resultado)); // Value = string
cmd.Parameters.Add(new OleDbParameter("@selecionar", cal.Selecionar));// Value = int
cmd.Parameters.Add(new OleDbParameter("@null", DBNull.Value));
cmd.CommandText = "INSERT INTO [Movimento Ferramentas] VALUES (@codigo, CAST(@data AS DATETIME), @entidade, @null, @null, 'Calibração', @null, @observacao, @null, @certificado, @resultado, @selecionar, @null)";
The table is defined like this ( column = fieldtype):
- Codigo = text
- Data saida (aka @data) = date/hour
- Entidade = text
- Data Ent = data/hour
- GT Ent = text
- Estado = text
- GT saida = text
- observacaoes = text
- requisitante = number
- certificado = text
- resultado = text
- selecionar = Yes/No
- tipo int = text
First I was getting an error saying "Data Type Mismatch In Criteria Expression" then I looked up the Cast for the date and put it like that and now it's giving me an error on it saying something like "Syntax error (operator missing) in the expression of the query CAST(@data AS DATETIME)"
Please help.
UPDATE: As suggested by @Ralph, I actually just had to put all nulls as nulls instead of going with the "@null", DBNull.Value. So, Problem Solved Thanks everyone.