none
use of unassigned local variable for data table RRS feed

  • Question

  • I am using the following code in C# window based application

    DataTable _dtTable;
    frmVehicle frm = new frmVehicle(_dtTable);  Here the unassigned local variable error is coming. 
    frm.Show();

    How can I get rid of that error message. 

    Pol


    polachan

    Friday, December 29, 2017 11:15 PM

Answers

  • DataTable _dtTable;
    frmVehicle frm = new frmVehicle(_dtTable);  Here the unassigned local variable error is coming. 
    frm.Show();

    How can I get rid of that error message.

    Since it's not obvious how frmVehicle(_dtTable) is using _dtTable it's
    difficult to tell you *exactly* what you need to do. In the absence of
    more details, you might try this change:

    DataTable _dtTable = new DataTable();

    - Wayne

    • Marked as answer by polachan Saturday, December 30, 2017 7:42 AM
    Saturday, December 30, 2017 12:27 AM

All replies

  • DataTable _dtTable;
    frmVehicle frm = new frmVehicle(_dtTable);  Here the unassigned local variable error is coming. 
    frm.Show();

    How can I get rid of that error message.

    Since it's not obvious how frmVehicle(_dtTable) is using _dtTable it's
    difficult to tell you *exactly* what you need to do. In the absence of
    more details, you might try this change:

    DataTable _dtTable = new DataTable();

    - Wayne

    • Marked as answer by polachan Saturday, December 30, 2017 7:42 AM
    Saturday, December 30, 2017 12:27 AM
  • Why would you be referencing _dtTable that was never instanced to be a datatable object and passing it into another class? When is _dtTable instanced and used, because it is not used in the class that defined it?
    Saturday, December 30, 2017 3:06 AM
  • You need to use DataTable _dtTable = new DataTable();

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, December 30, 2017 3:12 AM
    Moderator
  • You need to use DataTable _dtTable = new DataTable();

    Isn't that exactly what I suggested?

    - Wayne

    Saturday, December 30, 2017 3:31 AM
  • You need to use DataTable _dtTable = new DataTable();

    Isn't that exactly what I suggested?

    - Wayne

    oh, you mean this, because OO is OO?

    https://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

    Saturday, December 30, 2017 5:26 AM