在没有stoared程序的情况下在db中存储和恢复图像。 [英] image storing and retriving in db without stoared procedure.

查看:84
本文介绍了在没有stoared程序的情况下在db中存储和恢复图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;

namespace image
{
    public partial class Form1 : Form
    {
        string ss;
        byte[] buffer;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FileStream fileStream = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read);
            buffer = new byte[fileStream.Length];
            fileStream.Read(buffer, 0, (int)fileStream.Length);
           // ss = buffer.ToString();
            SqlConnection con = new SqlConnection(@"Data Source=KIRAN-PC\SQLEXPRESS;Initial Catalog=img;Integrated Security=True");

            string s = "insert into image1(image) values("+buffer+");";
            try

            {
                con.Open();
                SqlCommand cmd = new SqlCommand(s, con);
                int i = cmd.ExecuteNonQuery();
                if (i > 0)
                {
                    MessageBox.Show("Inserted......");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            fileStream.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            DialogResult res = dlg.ShowDialog();
            textBox1.Text = dlg.FileName;
            pictureBox1.Image = Image.FromFile(textBox1.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //Byte[] b1 = Convert.ToByte(ss);

            char[] c = ss.ToCharArray();
            MemoryStream memStream = new MemoryStream();
            memStream.Write(buffer, 0, buffer.Length);
            pictureBox1.Image= Image.FromStream(memStream);
        }
    }
}





string s =插入image1(图像)值( + buffer +);;我们设计了一个表并在其中获取了一个字段图像。缓冲区以字节格式保存图像。但它在保存dataabase时显示问题请提供消息解决方案..

请参阅还让我了解我们应该使用哪种数据类型来保存图像..pls..pls ...



string s = "insert into image1(image) values("+buffer+");";we designed a table and take a field image in it.and buffer saves the image in byte format.but it showing problem in saving dataabase pls provide messolution..
pls also give me idea about which datatype we should use to save the image..pls..pls...

推荐答案

检查此链接。会有更好的主意。

使用Microsoft .NET从SQL Server存储和检索图像 [ ^ ]
check this link. will get a better idea.
Storing and Retrieving Images from SQL Server using Microsoft .NET[^]


这篇关于在没有stoared程序的情况下在db中存储和恢复图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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