如何使用还包括图像的sqldatareader从数据库中检索数据 [英] how toretrive data from a database using sqldatareader including image also
本文介绍了如何使用还包括图像的sqldatareader从数据库中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用了包含empid,empname,empimage的表..
nowi还想使用包括图像在内的datareader从前端存储数据并从后端检索数据..
empid:1
empname:xxx
empimage:图片网址中的图片
i have employ table which contains empid,empname,empimage..
nowi want to store data from front and retrive data from backend using datareader including image also..
empid:1
empname:xxx
empimage:hisimage in image url
推荐答案
tryADO.NET
该链接将为您提供帮助:)
http://msdn.microsoft.com/en-us/library/h43ks021 (v = vs.71).aspx [ http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx [ ^ ]
http://blogs.sitepoint.com/introduction-ado-net/ [
tryADO.NET
this links will help you :)
http://msdn.microsoft.com/en-us/library/h43ks021(v=vs.71).aspx[^]
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx[^]
http://blogs.sitepoint.com/introduction-ado-net/[^]
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.Data.SqlClient;
using System.IO;
using System.Drawing.Imaging;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Data Source=VARNAR12;Initial Catalog=master;Integrated Security=True");
SqlCommand com = new SqlCommand();
static MemoryStream ms;
SqlDataReader dr;
public Form1()
{
InitializeComponent();
SqlCommand com = new SqlCommand("SELECT picid, " + "picdata FROM pic ORDER BY picid", con);
dr = default(SqlDataReader);
con.Open();
dr = com.ExecuteReader();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click_1(object sender, EventArgs e)
{
<pre lang="cs">if (dr.Read())
{
label1.Text = dr[0].ToString();
byte[] pic1 = new byte[dr.GetBytes(1, 0, null, 0, int.MaxValue)];
dr.GetBytes(1, 0, pic1, 0, pic1.Length);
MemoryStream stmdata = new MemoryStream(pic1);
pictureBox1.Image = Image.FromStream(stmdata);
}
dr.Close();
}
}
}
这篇关于如何使用还包括图像的sqldatareader从数据库中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文