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
相关文档:
using System.Text.RegularExpressions;
string ohtml = this.TextBox1.Text;
System.Text.RegularExpressions.MatchCollection m;
//提取字符串的图片
......
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 ......
asp.net(c#)网页跳转七种方法小结
发布时间:2009-11-25 11:13:03
1.Response.Redirect("http://www.yayiba.com",false);
目标页面和原页面可以在2个服务器上,可输入网址或相对路径。后面的bool值为是否停止执行当前页。
跳转向新的页面,原窗口被代替。"
浏览器中的URL为新路径。
:Response.Redirect方 ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient; //引用命名空间
namespace DAL
{
/*******************************************************************************
&n ......
下面这段C# 代码可以用来压缩和修复Access数据库,不管它是一个简单的".mdb"ACCESS数据库还是一个".mdw"网络共享数据库,这个过程和你在用MS Access应用程序中使用的"工具-数据库实用工具-压缩和修复"时执行的操作完全一样.实例代码使用了"迟绑定"(运行中在内存中建立COM对象),这样就不需要在工程中加入COM引用了,也不需要在P ......