I have a mysql unknown column error 1054. i can't insert in my database table my insert function
public void Insert(string tablename ,string[] values, string[] columns)
{
string col = "(";
for (int x = 0; x < columns.Length; x++)
{
if (columns[x] == columns.Last())
col += columns[x];
else
if (columns.Length > 1)
col += columns[x] + ",";
}
col += ")";
string val = "VALUES"+"(";
for (int x = 0; x < values.Length; x++)
{
if (values[x] == values.Last())
val += values[x];
else
if (values.Length > 1)
val += values[x] + ",";
}
val += ")";
string query = "INSERT INTO "+ tablename + col + val ;
my query: return from the function.
"INSERT INTO rezervationinformations(Fullname,Phone,Description)VALUES(dsa,cq,q)"
called function:
db.Insert("rezervationinformations", new string[] { textBox1.Text, textBox2.Text,
textBox3.Text }, new string[] { "Fullname", "Phone", "Description" });
What you are trying to achieve is really bad, and not only it will cause errors, it is also exposing your database to SQL injection.
Just forget this useless function and use vanilla
ADO.NET
with parametrized query.Or you can always use an ORM such as Entity Framework