net中的文件容器列与sql中的连接

net中的文件容器列与sql中的连接

本文介绍了ado.net中的文件容器列与sql中的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的大家,
我需要在ADONet中显示一列,其中包含.doc,.pdf.xsl等文件格式的骄傲信息,但我担心在哪里可以获取此信息以及如何在sql中存储任何文件,因此在运行时可以具有此功能的ADO.net网格视图中的fetchet.
这是我对所有人的谦虚要求,请给我适当的解决方案.
例如:-1.具有自豪名称的表包含字段ID,名称,价格,信息.
注意:-信息将包含文件(.doc,.xls.pdf等).

Dear ALL,
I need to dislplay a column in ADONet which contains proudct Information in file format like .doc,.pdf.xsl etc.But I''m worried where to fetch this info and how to store any file in sql thus in runtime it can be fetchet in grid view in ADO.net with this feature.
It''s my humble request to all,plz give me proper solution for this.
For example:- 1. A table with proudct name contains Fields ID,Name,Price,Info.
Note:- Info will contain file(.doc,.xls.pdf etc).

推荐答案

SqlDataReader dReader = cmd.ExecuteReader();

if (dReader.HasRows)
{
  while (dReader.Read())
  {
     context.Response.BinaryWrite((byte[])dReader["a_data"]);
  }

  dReader.Close();
}







protected void ShowImageOrPdf(object sender, GridViewRowEventArgs e)
{
const string LINK = "handler.ashx?Id={0}&Type={1}";
    GridView gv = (GridView)sender;

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string assessmentID = gv.DataKeys[e.Row.RowIndex].Value.ToString();
        bool isPDF =  (bool)e.Row.DataItem["IsPDF"];
        HyperLink h = new HyperLink();

        if (isPDF)
        {
            //render a link showing that it's a PDF.
            h.NavigateUrl = string.Format(LINK, assessmentID, "PDF");
            h.ImageUrl = "http://www.adobe.com/images/pdficon_large.gif";
            h.Text = "View PDF";
        }
        else
        {
            //render a thumbnail with a link to the image
            h.NavigateUrl = string.Format(LINK, assessmentID, "IMG");

            //have the handler create a thumbnail somehow.
            h.ImageUrl = string.Concat(h.NavigateUrl + "&Size=Small");
        }
       //write the link back to the placeholder.
       e.Row.FindControl("ph1").Controls.Add(h);
    }
}


SqlConnection cn=new SqlConnection("YourConnString");

String query = @"INSERT INTO ImagesStore (ImageBuffer) Values (@data)";

SqlCommand cmd=new SqlCommand(query,cn);
byte []barray=System.IO.File.ReadAllBytes(FileNamePath);

cmd.Parameters.Add("@data",SqlDbType.Image,barray.Length).Value=barray;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();


这篇关于ado.net中的文件容器列与sql中的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:04