but didtnt work well!!
M in Website: and i need profile iamges of each user to be stored in databse:
so in my form i put file [browse button] and an asp button for saving :
can post codes for this?
MYsql and C#.net
pls help me!!!
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lalit MRank #1,186 · 1.5K reputationPosted Feb 4, 2010, 11:18 PM EST
public class DataAccess { private string _strConn = @"Driver= {MySQLODBC 3.51 Driver};SERVER=localhost;DATABASE=test;"; private OdbcConnection _objConn; public DataAccess() { this._objConn = new OdbcConnection(this._strConn); } // This function adds the Images to database public string addImage(byte [] buffer,string extension) { string strSql = "SELECT * FROM File"; DataSet ds = new DataSet("Image"); OdbcDataAdapter tempAP = new OdbcDataAdapter(strSql,this._objConn); OdbcCommandBuilder objCommand = new OdbcCommandBuilder(tempAP); tempAP.Fill(ds,"Table"); try { this._objConn.Open(); DataRow objNewRow = ds.Tables["Table"].NewRow(); objNewRow["Extension"] = extension; objNewRow["Data"] = buffer; ds.Tables["Table"].Rows.Add(objNewRow); // trying to update the table to add the image tempAP.Update(ds,"Table"); } catch(Exception e){return e.Message;} finally{this._objConn.Close();} return null; } // This function to get the image data from the database public byte [] getImage(int imageNumber) { string strSql = "SELECT * FROM File"; DataSet ds = new DataSet("Image"); OdbcDataAdapter tempAP = new OdbcDataAdapter(strSql,this._objConn); OdbcCommandBuilder objCommand = new OdbcCommandBuilder(tempAP); tempAP.Fill(ds,"Table"); try { this._objConn.Open(); byte [] buffer = (byte [])ds.Tables["Table"].Rows[imageNumber]["Data"]; return buffer; } catch{this._objConn.Close();return null;} finally{this._objConn.Close();} } // Get the image count public int getCount() { string strSql = "SELECT COUNT(Data) FROM File"; DataSet ds = new DataSet("Image"); OdbcDataAdapter tempAP = new OdbcDataAdapter(strSql,this._objConn); OdbcCommandBuilder objCommand = new OdbcCommandBuilder(tempAP); tempAP.Fill(ds,"Table"); try> { this._objConn.Open(); int count = (int)ds.Tables["Table"].Rows[0][0]; return count; } catch{this._objConn.Close();return 0;} finally{this._objConn.Close();} } }Show here more info
Rujuta133 reputationPosted Feb 5, 2010, 12:42 AM EST
Now
use this code
HttpPostedFile img;
img = FileUpload.PostedFile;
Byte[] bt = new Byte[img.ContentLength];img.InputStream.Read(bt, 0, img.ContentLength);
when you use the insert query for the column with image datatype insert the value bt!
Hope this helps you.......