本文介绍了我如何将Command.ExecuteScalar()转换为可空类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private static int GenerationId()
{
OleDbCommand Command = new OleDbCommand();
Command.Connection = ConnectionDB.OLEConnection;
Command.CommandText = "Select MAX(Client_ID) from Client";
ConnectionDB.OLEConnection.Open();
int? Client_ID = (int?)CommandGenerationId.ExecuteScalar(); //i get exception here
ConnectionDB.OLEConnection.Close();
return (int)Client_ID;
}
推荐答案
Object tempVal = CommandGenerationId.ExecuteScalar();
Int32 returnVal;
if (tempVal != null)
returnVal = Int32.Parse(tempVal);
这些内容。对我来说,这种方法比尝试将其塞入一行更好。
Something along those lines. For me, this approach works better than trying to cram it into a single line.
这篇关于我如何将Command.ExecuteScalar()转换为可空类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!