I have a query in a TableAdapter that wrapped this SQL (Oracle SQL, uses ‘:’ instead of ‘@’ for parameterized variable), which I called GetModel()
SELECT MFG_PRODUCT FROM FRAME_NO
WHERE FRM_NO = :FRM_NO
I expected the query might return null values, so I set the column MFG_PRODUCT null value to be Null as pointed by this guideline from Microsoft
http://msdn.microsoft.com/en-us/library/ya91ataz(v=vs.100).aspx
However, my application still throw exception when the query returned no rows. What should I do?
I have rebuild the whole solution just in case that the code still referencing the old compiled dataset, but still, no luck.
Edited: Here is the code. The exception is thrown when the returned value is null
try
{
String modelCode = frameAdapter.GetModelCode(txtStdFrameId.Text.Trim()).ToString();
if(String.IsNullOrEmpty(modelCode)) //Go directly to exception when data is null here
{
//Process the data
}
}
catch(Exception ex)
{
//Log error to a text file
}
Setting a column to
NULLthis way does not have anything to do with your empty data rows. It will only work if you have at least one row and columns in that row areNULLFor data returning no rows, you will have to handle this case yourself