Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
All of you

I m developing project of lab management system in windows application plateform..

All the thing is done but A module is for uploading Downloading file is there thats make me try ..
Coz it takes my one weak but not solved yet..


Please help me

Thank uuuuuu

Advance..

[edit]SHOUTING removed - OriginalGriff[/edit]

[edit2]Additional information moved from non-solution below - Nelek[/edit2]
C#
if (txtDesc.Text == "" || cbxBatch.Text == "" || cbxSubjectCode.Text == "" || dtPicker.Text == "")
                {
                    MessageBox.Show("PLEASE FILL ALL FIELD", "ERROR");
                    return;
                }
                byte[] FileData;
                XMLDOCUMENTATION objXMLDOCUMENTATION = new XMLDOCUMENTATION();

                if (openFileDialog1.FileName != "openFileDialog1")
                    FileData = File.ReadAllBytes(lblFilePath.Text);
                else
                {
                    MessageBox.Show("PLEASE SELECT FILE TO UPLOAD", "ERROR");
                    return;
                }
                BUSINESSLAYER objBUSINESSLAYER = new BUSINESSLAYER();
                Hashtable ht = new Hashtable();
                ht.Add("@BATCH", cbxBatch.Text);
                ht.Add("@SUBJECT_CODE", Int32.Parse(cbxSubjectCode.Text));
                ht.Add("@PAPERNAME", txtDesc.Text);
                ht.Add("@CONTENTTYPE", lblContentType.Text);
                ht.Add("@ACTUALFILENAME", lblFileName.Text);
                ht.Add("@FILEDATA", FileData);
                ht.Add("@LASTDATE", dtPicker.Text.ToString());
                String Output = objBUSINESSLAYER.ExecuteSetProcedure("PAPERDETAILADDUPDATE", ht);
                if (Output == "SUCCESS")
                {
                    MessageBox.Show("YOUR PAPER IS SUCCESSFULLY SUBMITTED", "SUCCESSFULL");
                    openFileDialog1.Reset();
                    BindCombo(cbxBatch.Text, 0, "");
                }
                else
                    MessageBox.Show(Output, "ERROR");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "ERROR");
            }
this is the code for inserting data in sql server and

C#
try
           {
               int Row = e.RowIndex;
               if (e.ColumnIndex == 0)
               {
                   BUSINESSLAYER objBUSINESSLAYER = new BUSINESSLAYER();
                   dt = objBUSINESSLAYER.SqlDataAdapterQuery("SELECT ACTUALFILENAME,CONTENTTYPE,FILEDATA FROM PAPERDETAIL WHERE BATCH = '" + GrdPaperDetail.Rows[Row].Cells[1].Value.ToString() + "' AND SUBJECT_CODE = " + Int32.Parse(GrdPaperDetail.Rows[Row].Cells[2].Value.ToString()) + " AND ACTUALFILENAME = '" + GrdPaperDetail.Rows[Row].Cells[4].Value.ToString() + "'");
                   dr = objBUSINESSLAYER.ExecuteDataReader("SELECT ACTUALFILENAME,CONTENTTYPE,FILEDATA FROM PAPERDETAIL WHERE BATCH = '" + GrdPaperDetail.Rows[Row].Cells[1].Value.ToString() + "' AND SUBJECT_CODE = " + Int32.Parse(GrdPaperDetail.Rows[Row].Cells[2].Value.ToString()) + " AND ACTUALFILENAME = '" + GrdPaperDetail.Rows[Row].Cells[4].Value.ToString() + "'");
                   if (dr.Read())
                   {
                       File.WriteAllBytes(@"C:\" + dr["ACTUALFILENAME"], (byte[])dr["FILEDATA"]);
                       MessageBox.Show(@"FILE SAVE SUCCESSFULLY AT C:\" + dr["ACTUALFILENAME"], "SUCCESSFULL");
                   }
                   //if (true)
                   //{
                   //    File.WriteAllBytes(@"C:\" + dt.Rows[0].ToString(), (Byte[])dt.Rows[2].ToString());
                   //    //objBUSINESSLAYER.download(dt);
                   //}
                   //else
                   //    MessageBox.Show("MAKE SURE YOU HAVE CHOOSEN CORRECT FILE", "WARNING");
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message.ToString(), "ERROR");
           }

this is code for retreiving and i can not get the actual output .means output data is not same as inserted data ..
Posted
Updated 2-Nov-12 6:45am
v3
Comments
a1mimo 1-Nov-12 8:22am    
What have you done so far? add your code so we can help
Mangal Deep Gupta 1-Nov-12 8:42am    
i dont have i idea to do anything for storing and retrieving data from sql server of word file
OriginalGriff 1-Nov-12 8:58am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

Try:
C#
byte[] data = File.ReadAllBytes(path);
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myFileColumn) VALUES (@MFD)", con))
        {
        com.Parameters.AddWithValue("@MFD", data);
        com.ExecuteNonQuery();
        }
    }

And:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT myFileColumn FROM myTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            if (reader.Read())
                {
                File.WriteAllBytes(path, (byte[]) reader["myFileColumn"];
                }
            }
        }
    }
 
Share this answer
 
Comments
OriginalGriff 2-Nov-12 4:37am    
I take it you worked out what "path" means then...
Now all we have to do is get you to use the code as supplied instead of changing it and assuming it is the fault of the original code, instead of your mods?
The code above does not use DataRows...so it can't be trying to convert them. An SqlDataReader returns an Object when indexed.
OriginalGriff 2-Nov-12 5:54am    
Would you care to try explaining that in English?
OriginalGriff 2-Nov-12 6:23am    
In what way? What is the difference between the input and output?
(Remember I can't see your screen!)
C#
using (SqlConnection con = new SqlConnection(strConnect))
              {
              con.Open();
              using (SqlCommand com = new SqlCommand("SELECT myFileColumn FROM myTable", con))
                  {
                  using (SqlDataReader reader = com.ExecuteReader())
                      {
                      if (reader.Read())
                          {
                          File.WriteAllBytes(path, (byte[]) reader["myFileColumn"];
                          }
                      }
                  }
              }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900