Home > Net >  About the Data is Null.
About the Data is Null.

Time:12-21

I am to have such a database entity

Classs a

[the Display (Name="Name")]
Public string name {get; set; }

[the Display (Name="gonghaowu")]
Public string id_card {get; set; }

[Required (ErrorMessage="please enter the asset number")]
[the Display (Name="asset number")]
Public string pc_code {get; set; }

[the Display (Name="creation time")]
Public DateTime? Create_time {get; set; }

Added [Required (ErrorMessage="please enter the asset number")] this line

The repository data that was read out, if free this field will be an error inside the

I need now is, write new in this field cannot be empty of

Free, but before a repository can be normal read

An unhandled exception occurred while processing the request.
SqlNullValueException: Data is Null. This method or property always be called on Null values.
Microsoft. The Data. SqlClient. SqlBuffer. ThrowIfNull ()




CodePudding user response:

Two roads
Either the database with the update statement of Null values to an empty string, such as update TableName set ColName='where ColName is Null
Or is the judgment when you read from the database system. Dbnull. Value, is replaced with an empty string

CodePudding user response:

"The data repository read" how to write?

DBNull database value read from the ado.net need to decide, for example,
 if (value=https://bbs.csdn.net/topics/=DBNull. Value) 
Xd=string. The Empty;
The else
Xd=(string) res;

CodePudding user response:

The
refer to the original poster cpp_1 response:
I need now is, new, write entered this field cannot be empty

Free, but before a repository can be normal read


You write "new in" how should test by yourself, you will have to be read from the database inside out processing DBNull,
  • Related