使用Windows应用程序中的c#从数据库中检索filedata(ms word,.txt) [英] Retrieve filedata(ms word ,.txt) from database using c# in windows application

查看:110
本文介绍了使用Windows应用程序中的c#从数据库中检索filedata(ms word,.txt)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

所有人



我正在开发Windows应用程序平台中的实验室管理系统项目.. < br $>


所有的事情都已经完成但是一个模块用于上传下载文件就是那些让我试试..

因为它需要我的弱者但还没有解决..





请帮帮我



谢谢uuuuuu



预付..



SHOUTING删除 - OriginalGriff [/ edit]



[edit2]从下面的非解决方案转移的附加信息 - Nelek [/ edit2]

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]

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");
            }

这是在sql server中插入数据的代码和



this is the code for inserting data in sql server and

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");
           }



这是用于检索的代码,我无法获得实际输出.means输出数据与插入的数据不同。


this is code for retreiving and i can not get the actual output .means output data is not same as inserted data ..

推荐答案

尝试:

Try:
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:

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"];
                }
            }
        }
    }


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"];
                          }
                      }
                  }
              }


这篇关于使用Windows应用程序中的c#从数据库中检索filedata(ms word,.txt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆