tags:

views:

27

answers:

2

Hi, I have a problem with this code, maybe you can give me a hand. Im inserting file information as rows with name, size, ... they are all varchars The problem is that the "name" has this ' tildes in the namefile so when it tryies to parse the data it crashes.

the filename is : Creedence Clearwater Revival - Lookin' Out My Back Door - 09.mp3

after "lookin" there is a '

my command is: oleDbInsertCommand1.CommandText = "INSERT INTO Dirs-Arcs (nombre, formato, tamaño, path, tags) VALUES ('"+name+"', '"+formato+"', '"+tamaño+"', '"+path+"', '"+tags+"')";

this works fine with filenames without this ' characters, how can I parse this better???? thanks.

A: 

You may use AccessDataSource with parameters. If you use parameters, you dont have any problem for special chars.

ismailperim
+2  A: 

Use parameters:

OleDbCommand cmd = new OleDbCommand ( "INSERT INTO dirs-arcs (nombre, formato, tamano, path, tags) VALUES (@name, @format, @tamano, @path, @tags)", connection);

cmd.Parameters.Add( "@name", OleDbType.VarChar ).Value = name;
// add all parameters

hth

Mario

Mario The Spoon
Thanks Mario, that worked fine.I saw an example like this one before, but until now I didn't understand it.Thanks
HoNgOuRu
now I do. :)thank u
HoNgOuRu
You are welcome!
Mario The Spoon