You missed closing ')' in query.
MySqlCommand cmd = new MySqlCommand(" SELECT EXISTS(SELECT * from Appplication_Details WHERE FriendlyNameMS='" + Name + "')", conn);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello all,
i have been trying for a while now to check a database to see if a value exists by name in a row,
but keep getting syntax errors and Im totally lost how to get this to work,
this is what i have tried and the code i currently have ( code i tried is commented out )
public static bool check(string Name)
{
//MySqlCommand cmd = new MySqlCommand("SELECT COUNT (*) FORM Appplication_Details WHERE FriendlyNameMS='" + Name + "'", conn); SELECT EXISTS(SELECT * from ExistsRowDemo WHERE ExistId=105
MySqlCommand cmd = new MySqlCommand(" SELECT EXISTS(SELECT * from Appplication_Details WHERE FriendlyNameMS='" + Name + "'", conn);
object obj = cmd.ExecuteScalar();
if (Convert.ToInt32(obj) > 0)
{
return true;
}
else
{
return false;
}
}
thank you in advance elfenliedtopfan5
You missed closing ')' in query.
MySqlCommand cmd = new MySqlCommand(" SELECT EXISTS(SELECT * from Appplication_Details WHERE FriendlyNameMS='" + Name + "')", conn);
SELECT EXISTS (SELECT * from Appplication_Details WHERE …)
For MS SQL Server/T-SQL this construct with EXISTS in the SELECT would be invalid SQL statement and I can't imagine that MySQL supports this.
Your first query in comment ist the right one; beside the typo in FORM => FROM
MySqlCommand cmd = new MySqlCommand("SELECT COUNT (*) FROM Appplication_Details WHERE FriendlyNameMS='" + Name + "'", conn);
Thank you to both of your input both are correct i was just having a stupid moment i have looked back at it today and before even looking on here noticed that i made a mistake with the ) moral of the story don't code at 3:30 am haha