Answered by:
Find Replace

Question
-
User-735851359 posted
Hello,
I am trying to make a Find-Replace structure but it is working partially and giving error:
<form action="" method="post"> <div> Bul: <input type="text" name="bul" size="50" > </div> <div> Değiştir: <input type="text" name="degistir" size="50" > </div> <div> <input type="submit" name="submit" value="Değiştir"> </div> </form>
var info = data.Query("SELECT WordID, Meaning FROM EnglishWords ORDER BY WordID").ToList(); if(IsPost){ var bul = Request["bul"]; var degistir = Request["degistir"]; var w = ""; foreach(var word in info){ if(word.Meaning.Contains(bul)){ w = word.Meaning.Replace(bul, degistir); var sqlQ2 = "UPDATE EnglishWords SET Meaning=@0 WHERE WordID=@1 "; var res = data.Execute(sqlQ2, w, word.WordID); } }
The Error:
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
Line 9: if(word.Meaning.Contains(bul)){
Saturday, May 31, 2014 6:13 AM
Answers
-
User-821857111 posted
foreach(var word in info){ if(word.Meaning != null){ if(word.Meaning.Contains(bul)){ w = word.Meaning.Replace(bul, degistir); var sqlQ2 = "UPDATE EnglishWords SET Meaning=@0 WHERE WordID=@1 "; var res = data.Execute(sqlQ2, w, word.WordID); } } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, June 1, 2014 4:08 PM
All replies
-
User-1716253493 posted
Make sure Request["bul"] is not null, if null set bul with empty string.Saturday, May 31, 2014 6:21 AM -
User-735851359 posted
I imported a text with non-English characters and there non englısh characters are distorted while importing. I am trying to replace them forexample.
Д±
with
ı
Can the Request command accept that as Empty?
Saturday, May 31, 2014 6:30 AM -
User-821857111 posted
foreach(var word in info){ if(word.Meaning != null){ if(word.Meaning.Contains(bul)){ w = word.Meaning.Replace(bul, degistir); var sqlQ2 = "UPDATE EnglishWords SET Meaning=@0 WHERE WordID=@1 "; var res = data.Execute(sqlQ2, w, word.WordID); } } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, June 1, 2014 4:08 PM