Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>ok so i have solved the issue! I just had to go about it a bit of a different way:</p> <p>this is the important code:</p> <p>int mykey = int.Parse(ProjectPhotosList.DataKeys[e.ItemIndex].Value.ToString());</p> <p>its just a simple way to get the primarykey value of the selected row. I found a post about uploading pdf's to a database and decided to base the rest of my code on that. So here the full code:</p> <p>protected void ProjectPhotosList_ItemUpdating(object sender, ListViewUpdateEventArgs e)</p> <p>{</p> <p>FileUpload myFile = (FileUpload)ProjectPhotosList.EditItem.FindControl("uploadImage");</p> <pre><code> TextBox myCaption = (TextBox)ProjectPhotosList.EditItem.FindControl("ProjectPhotoCaptionTextBox"); int mykey = int.Parse(ProjectPhotosList.DataKeys[e.ItemIndex].Value.ToString()); if (myFile.HasFile) { //Get the posted file Stream fileDataStream = myFile.PostedFile.InputStream; //Get length of file int fileLength = myFile.PostedFile.ContentLength; //Create a byte array with file length byte[] fileData = new byte[fileLength]; //Read the stream into the byte array fileDataStream.Read(fileData, 0, fileLength); //get the file type string fileType = myFile.PostedFile.ContentType; //Open Connection PHJamesDataContext db = new PHJamesDataContext(); //Find the Right Row PHJProjectPhoto Newphoto = (from p in db.PHJProjectPhotos where p.ProjectPhotoId == mykey select p).Single&lt;PHJProjectPhoto&gt;(); Newphoto.ProjectPhoto = fileData; db.SubmitChanges(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload