NeCroFire

NeCroFire

  • NA
  • 86
  • 0

Save to database problem

Sep 25 2007 10:52 AM
It's a Acces database and I store file names in it.

This is my Command text:
insert.CommandText = "INSERT INTO CompleteListTable(Source, [File Name], [File Size], [Creation Date], Directory)VALUES('" + ListTable.Rows[i].Cells[y].Value.ToString() + "','" + ListTable.Rows[i].Cells[y + 1].Value.ToString() + "','" + ListTable.Rows[i].Cells[y + 2].Value.ToString() + "','" + ListTable.Rows[i].Cells[y + 3].Value.ToString() + "','" + ListTable.Rows[i].Cells[y + 4].Value.ToString() + "')";

It works fine... until there is a " ' ", like in "don't", in the value or some other type of character that can mess up the query... then it gives me an syntax error.

I thought of using these [] brackets before and after each comma, but then I get a "Incorrect use of brackets blah blah..." error.

What am I doing wrong, or what am I missing?

Answers (2)