To test some custom made mapping logic, I created a fake IDataRecord item.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IDataRecord CreateTestRecord() | |
{ | |
SqlDataRecord record = new SqlDataRecord( | |
new SqlMetaData("ID", SqlDbType.Int), | |
new SqlMetaData("PRODUCTNAME", SqlDbType.NVarChar)); | |
record.SetValues(1, "DUVEL"); | |
return record; | |
} |
However when I tried to run my test, it failed with the following error message:
The error message is not very explaining. The thing is that when you specify NVarChar as the dbType, you also have to specify the MaxLength. After doing that, the error was gone.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IDataRecord CreateTestRecord() | |
{ | |
SqlDataRecord record = new SqlDataRecord( | |
new SqlMetaData("ID", SqlDbType.Int), | |
new SqlMetaData("PRODUCTNAME", SqlDbType.NVarChar, 100)); | |
record.SetValues(1, "DUVEL"); | |
return record; | |
} | |