1

I am creating a System with tile buttons, User will add image to SQL database and when he load a form that image will load in a Picture box, I made a code to add an image to pictuew an image to picturebox and i waned to add them in to database with a button click event for that I code something like this.

string mySQL = "INSERT INTO Reservation VALUES ("
         + Convert.ToInt32(textBox_TileNo.Text.Trim()) + ", '"
         + textBoxItemCde.Text.Trim() + "','"
         + textBoxItemNme.Text.Trim() +
         + pictureBox.Image () + "')";
         DBConnection database = new DBConnection();
         int rslt = database.insertValues(mySQL);
         if (rslt > 0)
         {
             MessageBox.Show("added");
         }
         else
         {
             MessageBox.Show("Error wile adding data");
         }

this is giving me an error in this line + pictureBox.Image () + "')"; under .image i know this wont work, can anybody suggest me the correct way or Woking code like this

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Xeroth
  • 107
  • 1
  • 11
  • 2
    Use bind variables ([SO post here](http://stackoverflow.com/questions/7505808/using-parameters-in-sql-statements)). It will solve your problem and a few others you haven't yet thought about. Like what happens when someone enters "`x', NULL, NULL); DROP DATABASE; --`" in `textBoxItemCde.Text`. – nvoigt Mar 31 '14 at 17:48
  • it is normally adding the data if it is null, is any wrong in in i know this injunction method is not proper but i found this is a easy way – Xeroth Mar 31 '14 at 17:53
  • Please see this i think this help you http://stackoverflow.com/questions/15659835/how-to-store-image-in-sql-server-database-tables-column –  Mar 31 '14 at 17:51
  • which link ? ou never add any links – Xeroth Mar 31 '14 at 17:57
  • http://stackoverflow.com/questions/15659835/how-to-store-image-in-sql-server-database-tables-column –  Mar 31 '14 at 17:59

0 Answers0