The issue is that (as the error message indicates) the conditional expression needs either identical types on both branches, or else there needs to be an implicit conversion from one of the types to the other. In your case, there isn't one, and so you get the error. One quick fix would be cast one of the values to (object)
(which is fine, since DbParameter.Value
is of type object
anyway.)
So this should work for you:
param7[1].Value = tbLastName.Text.Length > 0 ? tbLastName.Text : (object)DBNull.Value;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…