I would like to know why my data is not saving permanently in my local database. If I close my application and open it again. I cannot download the uploaded data. Its showing an error called "The given key was not present in the dictionary” But I can download the file when the application is running. I mean, if the application is running and I upload a data to my grid, then i can download it without any error. If the application is closed and opened, that time if I try to download the same old file its throwing the error

My code

private void DownloadAttachment(DataGridViewCell dgvCell)
    {
        string fileName = Convert.ToString(dgvCell.Value);

        //Return if the cell is empty
        if (fileName == string.Empty)
            return;

        FileInfo fileInfo = new FileInfo(fileName);
        string fileExtension = fileInfo.Extension;

        byte[] byteData = null;

        //show save as dialog
        using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
        {
            //Set Save dialog properties
            saveFileDialog1.Filter = "Files (*" + fileExtension + ")|*" + fileExtension;
            saveFileDialog1.Title = "Save File as";
            saveFileDialog1.CheckPathExists = true;
            saveFileDialog1.FileName = fileName;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                cncInfoDataGridView.Rows[dgvCell.RowIndex].Cells[1].Value = fileInfo.Name;
                byteData = _myAttachments[dgvCell.RowIndex];
                File.WriteAllBytes(saveFileDialog1.FileName, byteData);
            }
        }
    }

Also if anybody could tell me a sample program to upload and download a file or document to/from the database.mdf and to view in
grid view with out using the sql server. because i dont want to use the sql server. Just using a local database.
Please anybody help me to find the right code.

Thanks in advance.

Recommended Answers

can you show me the code where you are saving data to database (local)?

Jump to Post

All 2 Replies

can you show me the code where you are saving data to database (local)?

I am doing the worong thing now. I am now saving in a dictionary. which acts like a RAM. I need to zip it and save in database. For that i need help. Can you guys help me.

Be a part of the DaniWeb community

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