I saw other similar questions, but I can't manage to apply other solutions.
Here is the code
Dim da1 As DateTime = DateTime.ParseExact(Date.Today, "dd/MM/yyyy", CultureInfo.InvariantCulture)
Dim dataQuery As String = da1.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture).PadLeft(10)
Dim errori = db.TRANSAZERROR.Where(Function(t) t.DATA.PadLeft(10) = dataQuery)
transazerror.data
is a nullable
varchar field (yes it's not a datetime) and it also contain a time, so I'm using padleft to get only the date in the format dd-MM-yyyy.
What I want is to select all record that have data=today
so the errori
var should be a list of records, but the code above returns
Nullreferenceexception
I don't know why.
I'm using EF 6.
Thanks for your hints!
Exception detail:
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Riferimento a un oggetto non impostato su un'istanza di oggetto.
Source=transazErrorLog
StackTrace:
in transazErrorLog.Form1.log() in I:\Documenti\Vs15_Projects\transazErrorLog\transazErrorLog\Form1.vb:riga 22
in transazErrorLog.Form1.Form1_Load(Object sender, EventArgs e) in I:\Documenti\Vs15_Projects\transazErrorLog\transazErrorLog\Form1.vb:riga 9
in System.EventHandler.Invoke(Object sender, EventArgs e)
in System.Windows.Forms.Form.OnLoad(EventArgs e)
in System.Windows.Forms.Form.OnCreateControl()
in System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
in System.Windows.Forms.Control.CreateControl()
in System.Windows.Forms.Control.WmShowWindow(Message& m)
in System.Windows.Forms.Control.WndProc(Message& m)
in System.Windows.Forms.Form.WmShowWindow(Message& m)
in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
InnerException:
EDIT: I tried to use another filed of the db, it's a date field set to nullable=false, even with this I get the nullreference exception... I turn the question around: how can I get a list of record using entity framework?