I'm calling the following code:
public static bool checkDuplicateProducts(string item1, string item2)
{
// new connection
SqlConnection con = new SqlConnection(stringCon);
// adapter query
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM '" + item1 + "' WHERE ProductCode='" + item2 + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count >= 1)
{
return true;
}
else
{
return false;
}
}
from this:
string tableName = "Product";
else if(Functions.checkDuplicateProducts(tableName, textBox2.Text) == true)
{
MessageBox.Show("The id is already available", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
I get this error when doing so:
System.Data.SqlClient.SqlException: 'Incorrect syntax near ' Product '.'