I am trying to run a if statement that checks if a string contains a word that's placed in a datatable but it does not work properly.
if (nickName.Contains(dt.Rows[1]["Word"].ToString()))
{
//something something
}
In this case Nickname is a string var which contains user inputs. dt is a datatable which contains words (I actually loop through this DT but that does not matter for this example)
But this does not work... even if I copy and paste the word.
I also noticed that just trying to this (Yes I'm sure that that spot in the DT is the word I'm trying to check)
if (dt.Rows[1]["Word"].ToString() == "some word")
Does not work (even when copy and pasting the word).
Do datatables store string in a funny way or something like that?
Do any of you have an solution?
(here is more of the code if you want)
//textboxes to vars
string nickName = tbtNickName.Text;
string tweet = tbTweet.Text;
//creating DT
var dt = new DataTable();
using (var da = new SqlDataAdapter("SELECT * FROM Words;", "Data Source=localhost;Initial Catalog=twtWall;User Id=<id>; Password=<password>"))
{
da.Fill(dt);
}
//for each element in an array chek if you are in any inputs
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
//if word detected set error
if (nickName.Contains(dt.Rows[i]["Word"].ToString()))
{
errorProvider.SetError(BtnTweet, "Bad word detected!");
}
//do the same thing with tweets...
}