Hi ycheehao,
This error is because you have cleared all DAQmx references and resources related to that task immediately after your first read. Move the Clear DAQmx Task outside the while loop so that it executes when you are ready to end your DAQ task. You can find good examples of DAQ programming in the Example Finder and also our DevZone article:
Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications- Develope...
PBear
NI RF