• 大小: 249.17 KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-10-02
  • 语言: 其他
  • 标签: C#  

资源简介

图片存储到数据库保存二进制文件,并在DATAGRIDVIEW中显示出来

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using Microsoft.VisualBasic.FileIO;
using System.xml;

namespace ImageDemo
{
    public partial class Form1 : Form
    {
        public string connectstring = ““;
        public string apppathstring = ““;
        public static SqlConnection padocnt;


        public Form1()
        {
            InitializeComponent();
        }

        //读取连接字符串
        public static string ReadConnectStr(out string servername out string dbname out string dbuser out string dbpwd)
        {
            servername = ““;
            dbname = ““;
            dbuser = ““;
            dbpwd = ““;
            try
            {
                //FileSystem.CurrentDirectory = Form1.apppathstring;
                //if (FileSystem.FileExists(“system.xml“) == false)
                //{
                //    return “no find configuration files“;
                //}
                //else
                //{
                    xmlDocument tmpdoc = new xmlDocument();
                    tmpdoc.Load(“system.xml“);
                    xmlNodeList tmplist = tmpdoc.SelectSingleNode(“title“).ChildNodes;
                    foreach (xmlNode tmpnode in tmplist)
                    {
                        xmlElement tmpxe = (xmlElement)tmpnode;
                        if (tmpxe.Name == “servername“)
                        {
                            servername = tmpxe.InnerText.ToString();
                        }
                        else if (tmpxe.Name == “dbname“)
                        {
                            dbname = tmpxe.InnerText.ToString();
                        }
                        else if (tmpxe.Name == “dbuser“)
                        {
                            dbuser = tmpxe.InnerText.ToString();
                        }
                        else if (tmpxe.Name == “dbpwd“)
                        {
                            dbpwd = tmpxe.InnerText.ToString();
                        }
                    }
                    return “ok“;
                //}
            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }


        private void SaveImage(string fileName)
        {
            // Read the file into a byte array
            using (FileStream fs = new FileStream(fileName FileMode.Open FileAccess.Read))
            {
                byte[] imageData = new Byte[fs.Length];
                fs.Read(imageData 0 (int)fs.Length);

                using (SqlConnection conn = new SqlConnection(connectstring))
                {
                    string id = string.Empty;
                    Random rand = new Random();
                    id = rand.Next(10 999999).ToString ();

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        682  2008-12-05 15:05  Image\Image\app.config

     文件     114688  2008-12-05 15:14  Image\Image\bin\Debug\Image.exe

     文件        682  2008-12-05 15:05  Image\Image\bin\Debug\Image.exe.config

     文件     253440  2008-12-05 15:14  Image\Image\bin\Debug\Image.pdb

     文件       5632  2005-12-08 14:51  Image\Image\bin\Debug\Image.vshost.exe

     文件        682  2008-12-05 15:05  Image\Image\bin\Debug\Image.vshost.exe.config

     文件        175  2008-12-05 14:41  Image\Image\bin\Debug\system.xml

     目录          0  2008-12-05 15:03  Image\Image\bin\Debug

     目录          0  2007-12-20 15:55  Image\Image\bin

     文件       8019  2008-12-05 15:14  Image\Image\Form1.cs

     文件      15215  2008-12-05 14:55  Image\Image\Form1.Designer.cs

     文件       7915  2008-12-05 14:55  Image\Image\Form1.resx

     文件      15086  2008-12-05 14:45  Image\Image\gc2.ico

     文件       7624  2008-12-05 14:44  Image\Image\ImageDemo.csproj

     文件     114688  2008-12-05 15:14  Image\Image\obj\Debug\Image.exe

     文件     253440  2008-12-05 15:14  Image\Image\obj\Debug\Image.pdb

     文件        842  2008-12-05 15:03  Image\Image\obj\Debug\ImageDemo.csproj.GenerateResource.Cache

     文件        180  2008-12-05 15:03  Image\Image\obj\Debug\ImageDemo.Form1.resources

     文件        180  2008-12-05 15:03  Image\Image\obj\Debug\ImageDemo.Properties.Resources.resources

     文件      36864  2008-12-05 15:05  Image\Image\obj\Debug\TempPE\pm3lnew_borshDataSet.Designer.cs.dll

     文件      36864  2008-12-05 15:05  Image\Image\obj\Debug\TempPE\pm3lnew_borshDataSet1.Designer.cs.dll

     文件      36864  2008-12-05 15:05  Image\Image\obj\Debug\TempPE\pm3lnew_borshDataSet2.Designer.cs.dll

     文件      36864  2008-12-05 15:05  Image\Image\obj\Debug\TempPE\pm3lnew_borshDataSet3.Designer.cs.dll

     文件      36864  2008-12-05 15:05  Image\Image\obj\Debug\TempPE\pm3lnew_borshDataSet4.Designer.cs.dll

     文件      36864  2008-12-05 15:05  Image\Image\obj\Debug\TempPE\pm3lnew_borshDataSet5.Designer.cs.dll

     目录          0  2008-12-05 15:05  Image\Image\obj\Debug\TempPE

     目录          0  2008-12-05 15:14  Image\Image\obj\Debug

     文件        294  2008-12-05 15:14  Image\Image\obj\ImageDemo.csproj.FileList.txt

     目录          0  2008-12-05 15:03  Image\Image\obj

     文件      45030  2007-12-20 16:17  Image\Image\pm3lnew_borshDataSet.Designer.cs

............此处省略39个文件信息

评论

共有 条评论