Hi All,
I am trying to store a link to a document in a mysql database using VB.NET. I open a file browser for the user to select the file, and if I output the returned filename to a messagebox it looks fine, but when I write that filename string to the SQL database it removes all of the backslash characters.

The messagebox output shows my filename string to be: C:\Temp\EULA.TXT
The field in the SQL database is: C:TempEULA.TXT

Is there a special data type I need to use (either in VB.net or in mysql) to store the filepathname? How can I stop it stripping out the '\' characters. I am currently storing it as a String in VB and as varchar(255) in mysql. Please note I am not trying to upload a file into the database, just store the filename and path.

thanks,
Toomutch

Recommended Answers

All 4 Replies

Are you using a parameterized query, are you concatenating the value into the insert statement, do you use datatables ?
Please share the code that inserts this into your db.

Did you try escaping the backslash with another one?

hai toomutch,

could you tell me the reason for storing the total path of the selected file into database?

Hi All,
Adam K got it spot on with the first reply! Two team points to you. I converted the code to use parameters rather than just list the values of the field and this cured the problem. I am new to SQL (although have been programming in other languages for 30+ years) and only found out about the benefits of passing parameters to an insert or update statement well into my current project.
@radhakrishna.p - I have a database containing all of our current engineering jobs. I wanted users to be able to 'attach' or link a document to each job (e.g. a scan of the jobsheet, or a PDF of the invoice for example). Any reason? Have I missed a trick somewhere?

Thanks to all who replied.
Toomutch

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.