易截截图软件、单文件、免安装、纯绿色、仅160KB

C#关于sqlserver中读取image类型

今天在网上找了许久关于sqlserver中存储image类型和读取image的方法,可是都是那么一点,故在此罗列一下,希望可以帮助大家。
首先是关于dataGridView的绑定。代码见下
private void button_show_Click(object sender, EventArgs e)
{
string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
string sqlstr="select * from tast";
SqlConnection conn=new SqlConnection (sqlText);
conn.Open();
SqlCommand comm = new SqlCommand(sqlstr, conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}
下面是插入图像到数据库,代码如下:
  private void button_connect_Click(object sender, EventArgs e)
{
string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
string sqlstr = "insert into tast(photo) values(@image) ";
SqlConnection conn = new SqlConnection(sqlText);
conn.Open();
SqlCommand comm = new SqlCommand(sqlstr, conn);
comm.Parameters.Add("@image", SqlDbType.Image).Value = GetPhoto("DSC_6126.JPG");
comm.ExecuteNonQuery();
conn.Close();
}
public byte[] GetPhoto(string str1)
{
string str = str1;
FileStream file = new FileStream(str, FileMode.Open, FileAccess.Read);
byte[]photo=new byte[file.Length];
file.Read(photo,0,photo.Length);
file.Close();
return photo;
}
下面就是读取图片了
private void button_showimg_Click(object sender, EventArgs e)
{
string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
string sqlstr = "select *from tast where whf=1";
SqlConnection conn = new Sql


相关文档:

js C# ASP.Net 正则去掉超链接(只是 和 )

//替换所有
Regex reg = new Regex(@"(?is)</?a\b[^>]*>(?:(?!</?a).)*</a>");
string result = reg.Replace(yourStr, "");
//保留www.abc.com链接
Regex reg = new Regex(@"(?is)</?a\b.*?href=(['""]?)(?!(?:http://)?www\.abc\.com)[^'""\s>]+\1[^>]*>(?<text>(?:(?!</?a).) ......

c#从html中获取图片地址

 
using System.Text.RegularExpressions;
string ohtml = this.TextBox1.Text;
            System.Text.RegularExpressions.MatchCollection m;
            //提取字符串的图片
   ......

c#:Dataset读取XML文件动态生成菜单

Step 1:Form1 上添加一个ToolStripContainer控件
Step2:实现代码
private void Form2_Load(object sender, EventArgs e)
{
    CMenuEx menu = new CMenuEx();
    string sPath = "D:\\Menu.xml";//xml的内容
     if (menu.FileExit())
  &nb ......

C#中用于连接SQL数据库的SQLHelper类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;   //引用命名空间
namespace DAL
{
    /*******************************************************************************
  &n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号