I have a funky problem.. I have this code:
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = this.connection;
cmd.CommandText = "SELECT id FROM links WHERE url LIKE '@url'";
cmd.Parameters.AddWithValue("@url", parent_url.Trim());
cmd.Prepare();
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
parent_id = reader.GetInt32(0);
}
}
}
What my problem is that.. sometimes it doesn't return a value when there is a an answer in the database. That's very strange. Also I have noticed that some items in the database have a space behind it so this is why I made this:
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = this.connection;
cmd.CommandText = "SELECT id FROM links WHERE url LIKE '@url'";
cmd.Parameters.AddWithValue("@url", parent_url.Trim());
cmd.Prepare();
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
parent_id = reader.GetInt32(0);
}
}
}
if(parent_id == 0)
{
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = this.connection;
cmd.CommandText = "SELECT id FROM links WHERE url LIKE '@url '";
cmd.Parameters.AddWithValue("@url", parent_url.Trim());
cmd.Prepare();
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
parent_id = reader.GetInt32(0);
}
}
}
}
But it still doesn't help me some times.. even if the item doesn't have a space after it. So yea.. can you guys please give me some advice.. what should I try.
urlin the database table?