| | |
Save and Retrive Image
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#22 Oct 23rd, 2009
I used this code to save the image to the folder
Then this code to insert the filename (fileName into the mysql database
which was successful. So after I was able to save the file into the folder and the fileName(not including the weird character) into the db, I expected to find only the filename not other characters attached to the fileName
C# Syntax (Toggle Plain Text)
string chosen_file = ""; string file = ""; chosen_file = openFD.FileName; string fileName = System.IO.Path.GetFileNameWithoutExtension(chosen_file); MemberPics.Image = Image.FromFile(chosen_file); MemberPics.Image.Save(string.Format("d:\\Pictures\\{0}.jpg", fileName), System.Drawing.Imaging.ImageFormat.Jpeg); file = fileName;
Then this code to insert the filename (fileName into the mysql database
C# Syntax (Toggle Plain Text)
string strSQL = "INSERT INTO memberinfo " + "(memberid,memberSname,memberFname, fileName)" + "VALUES( '" + txtmid.Text + "','" + txtmSname.Text + "','" + txtFname.Text + "', '" + file +"')"; accessDB.myCmd(strSQL).ExecuteNonQuery();
•
•
Join Date: Jul 2009
Posts: 972
Reputation:
Solved Threads: 213
0
#23 Oct 23rd, 2009
I am going to BUMP on this one because nothing I can see to cause that string assignment to occur that way.
I assume you added the following lines to try to elliminate the problem:
but, you shouldn't need to be doing that either given the code I've seen. Also, I have not used those calls in a string.Trim before--have you tried it without those two lines?
Anyway, I've got somewhere I need to get to... Just post back a response and someone else will surely look into this before I get back.
I assume you added the following lines to try to elliminate the problem:
C# Syntax (Toggle Plain Text)
path = path.Trim(Path.GetInvalidFileNameChars()); path = path.Trim(Path.GetInvalidPathChars());
but, you shouldn't need to be doing that either given the code I've seen. Also, I have not used those calls in a string.Trim before--have you tried it without those two lines?
Anyway, I've got somewhere I need to get to... Just post back a response and someone else will surely look into this before I get back.
•
•
Join Date: Oct 2009
Posts: 63
Reputation:
Solved Threads: 17
0
#24 Oct 23rd, 2009
The column in your database that holds the filename might be a char data type column (or wchar, etc), if you change it to varchar (or nvarchar, etc) then it will let you use variable length strings and not give you all those extra zeros.
The other choice (off the top of my head) is to change line 29 to this:
Edit: (for some reason I think the char data type pads with spaces, not zeros, so the column data type couple be wrong. Also, I forget if Trim() removes zeros like this, you might need to call instead which specifically removes the zeros ... I think
The other choice (off the top of my head) is to change line 29 to this:
C# Syntax (Toggle Plain Text)
String path = ("d:\\Pictures\\" + img.Trim() + ".jpg");
Edit: (for some reason I think the char data type pads with spaces, not zeros, so the column data type couple be wrong. Also, I forget if Trim() removes zeros like this, you might need to call
C# Syntax (Toggle Plain Text)
img.Trim(new char[] {'\0'})
Last edited by mikiurban; Oct 23rd, 2009 at 4:53 pm. Reason: Disclaimer: I just ate a giant chicken parmesan, I blame all errors to impending food coma :)
0
#26 Oct 23rd, 2009
What in the world are you doing? Try to use the code I provided you and get it working. Then modify the code to do what you want it to .. and find out where it breaks.
•
•
Join Date: Oct 2009
Posts: 63
Reputation:
Solved Threads: 17
1
#27 Oct 23rd, 2009
sknake has a point (and no, he doesn't pay me to agree with him), calling .Replace() will fix this problem for now, but what you really want to do is understand why it's happening in the first place, or else your program will have a million Replace() commands. My money is on the data stored as char instead of varchar in the DB.
I doubt this is the problem, but you might want to be careful with this line:
If any of those text boxes have an apostrophe in there, the insert will break. I suggest using (or OdbcCommand, I forget which is for MS Access) to prevent any kind of query hacking shenanigans.
I doubt this is the problem, but you might want to be careful with this line:
C# Syntax (Toggle Plain Text)
string strSQL = "INSERT INTO memberinfo " + "(memberid,memberSname,memberFname, fileName)" + "VALUES( '" + txtmid.Text + "','" + txtmSname.Text + "','" + txtFname.Text + "', '" + file +"')";
If any of those text boxes have an apostrophe in there, the insert will break. I suggest using
C# Syntax (Toggle Plain Text)
OleDbCommand cmd = new OleDbCommand(...); cmd.Parameters.AddWithValue(...)
0
#28 Oct 24th, 2009
•
•
•
•
sknake has a point (and no, he doesn't pay me to agree with him), calling .Replace() will fix this problem for now, but what you really want to do is understand why it's happening in the first place, or else your program will have a million Replace() commands. My money is on the data stored as char instead of varchar in the DB.
DBNull.Value . I call Convert.ToString() on all string values brought back and the NULL will equate to string.Empty . ![]() |
Similar Threads
- how to retrive image file from mysql databse using php (PHP)
- How to store a byte array in a database and retrive it back as byte array? (C#)
- How to Save data and image in a MSAccess Database using vb.net (VB.NET)
- save GDI+ image into sql 2005 database (C#)
Other Threads in the C# Forum
- Previous Thread: how to filter strange characters?
- Next Thread: SQL querry Combo Box Question
Views: 2011 | Replies: 27
| Thread Tools | Search this Thread |
Tag cloud for image
.net animation api applet array back backup bmp broken button byte c# checkbox clone cloning code datagram desktop directory disk displayimageinsteadofflash download drive embedded encode file flash format free gdi ghost google grid hard header hosting image images java jpanel jpeg link mediawiki method multimedia mysql open packets panel php picture picturebox problem random reading reputationmanagement resource screen scroll search shot subdomain swf swf. swing transfer udp upload url view wallpaper web webbrowser website windows







