TroubleShooting

DB ๊ฐ’ SetValue๋ฅผ ์ด์šฉํ•ด ๊ฐ’ Insert

S_sun 2025. 11. 25. 11:06

๐Ÿ”ฅ ๋ฌธ์ œ๋ฐœ์ƒ

  • ๊ฐ’์ด ์—ฌ๋Ÿฌ๊ฐœ๊ฐ€ ์กด์žฌํ•œ๋‹ค. (List)
  • DB์—์„œ๋Š” ์ปฌ๋Ÿผ์ด ์—ฌ๋Ÿฌ๊ฐœ๋กœ ๋‚˜๋‰˜์–ด Insert ํ•˜๋„๋ก ํ•ด์•ผํ•œ๋‹ค.
  • ์ฒ˜์Œ ๊ฐ’์„ Insert ํ•œ ํ›„, ๋’ค์— ๊ฐ’์€ ๋™์ผํ•œ ํ‚ค๋ฅผ ๋น„๊ตํ•˜์—ฌ update๋ฅผ ํ•ด์•ผํ•œ๋‹ค.
  • ์ฝ”๋“œ๊ฐ€ ๋„ˆ๋ฌด ๊ธธ์–ด์ง€๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

โญ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

  • ๊ฒฐ๊ณผ ๊ฐ’์„ ๋ฐ˜๋ณต๋ฌธ์„ ํ†ตํ•ด Reflaction ํ•˜์—ฌ ๊ฐ’์„ entity์— ๋„ฃ์–ด์ค€๋‹ค.
for (int i = 0; i < strResult.Count; i++)
{
    if (!string.IsNullOrEmpty(strResult[i]))
    {
        string[] splitStr = strResult[i].Split("|");
        //PropertyInfo property =  entity.GetType().GetProperties().FirstOrDefault(x => x.Name.Equals("ResultValue" + (i + 1)));
        //property.SetValue(entity, splitStr[1]);
        entity.GetType().GetProperties().FirstOrDefault(x => x.Name.Equals("ResultValue" + (i + 1))).SetValue(entity, splitStr[1]);
        entity.GetType().GetProperties().FirstOrDefault(x => x.Name.Equals("RecognitionConfidence" + (i + 1))).SetValue(entity, splitStr[2]);
        entity.GetType().GetProperties().FirstOrDefault(x => x.Name.Equals("DetectionConfidence" + (i + 1))).SetValue(entity, splitStr[3]);
    }
}

 

 

 

๐Ÿ“– Reference
 

C# Reflection - Object does not match target type

I'm trying to use the propertyInfo.SetValue() method to set an object property value with reflection, and I'm getting the exception "Object does not match target type". It doesn't really make sens...

stackoverflow.com

 

728x90
๋ฐ˜์‘ํ˜•

'TroubleShooting' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

parameters describe an un representable datetime  (0) 2025.11.27
VS SSL ์ธ์ฆ์„œ ์˜ค๋ฅ˜  (0) 2025.11.27
์•”๋ณตํ˜ธํ™”  (0) 2025.11.25
DB Multi-Insert  (0) 2025.11.25