我在我的代码中使用了GetOrdinal。代码
mastxtDateEnded_Edit.Text =
Convert.ToDateTime(cursor.GetValue(cursor.GetOrdinal("DateEnded")))
.ToString("MM/dd/yyyy"));
Error: object cannot be cast from DBNULL to ther types.
答案 0 :(得分:0)
您可以使用IsDBNull
method检查空值:
int index = cursor.GetOrdinal("DateEnded")
mastxtDateEnded_Edit.Text =
cursor.IsDBNull(index) ?
String.Empty :
((DateTime)(cursor.GetValue(index))).ToString("MM/dd/yyyy");