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

ASP.NET从SQL Server数据库提取图片并显示在DataGrid

使用Gridview绑定数据库中的图片(转载)
注:此系列记录在我实际开发中遇到的问题和收藏一些技巧文章。
我们都知道,在Gridview中不能直接去绑定数据库中的图片,我们可以利用HttpHandler很容易的完成这个任务,在这里我记录一下这个过程。
1.上传图片存储到数据库中
在数据库中创建一个表,添加一下3个字段:
步骤一:在Web页面中拖一个FileUpload 控件,一个文本框用于输入名称和提交上传按钮
<asp:FileUpload ID="fuImage" runat="server" /><br />
<asp:TextBox ID="txtImageName" runat="server"/><br />
<asp:Button ID="btnUpload" runat="server" onClick="btnUpload_Click" Text="Upload" />
步骤二:在Web.Config文件内配置连接字符串。
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\Image.mdf;Integrated Security=True;
User Instance=True" providerName="System.Data.SqlClient"/>
步骤三:把下面的代码复制到上传按钮事件中。
protected void btnUpload_Click(object sender, EventArgs e)
{
Stream imgStream = fuImage.PostedFile.InputStream;
int imgLen = fuImage.PostedFile.ContentLength;
string imgName = txtImageName.Text;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData,0,imgLen);

//use the web.config to store the connection string
SqlConnection connection = new SqlConnection(ConfigurationManager.
ConnectionStrings["connectionString"].ConnectionString);
SqlCommand command = new SqlCommand("INSERT INTO Image (imagename,image)
VALUES ( @img_name, @img_data)", connection);

SqlParameter param0 = new SqlParameter("@img_name", SqlDbType.VarChar, 50);
param0.Value = imgName;
command.Parameters.Add(param0);

SqlParameter param1 = new SqlParameter("@img_data", SqlDbType.Image);
param1.Value = imgBinaryData;
command.Parameters.Add(param1);

connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
}
2.利用HttpHandler从数据库中读取图片
创建


相关文档:

JAVA连接ACCESS,SQL Server,MySQL,Oracle

import java.sql.*;
/*
* JAVA连接ACCESS,SQL Server,MySQL,Oracle数据库
*
* */
public class JDBC {
  
public static void main(String[] args)throws Exception {
  
   Connection conn=null;
  
       //====连接ACCESS数据库 ......

使用SQLServer模板来写规范的SQL语句

如果你经常遇到下面的问题,你就要考虑使用SQL Server的模板来写规范的SQL语句了:
SQL初学者。
经常忘记常用的DML或是DDL SQL 语句。
在多人开发维护的SQL中,每个人都有自己的SQL习惯,没有一套统一的规范。
在SQL Server Management Studio中,已经给大家提供了很多常用的现成SQL规范模板。
SQL Server Management ......

ASP.NET Web 应用程序的布局

ASP.NET 应用程序必须位于 IIS 虚拟目录(也称为应用程序根目录)中。ASP.NET 应用程序可包含已编译的程序集(通常是包含业务逻辑的 DLL 文件)、用于存储预编译代码的已知目录(目录名总是 \Bin)、存储在基于文本的、易读的 Web.config 文件中的配置设置、页、服务器控件,以及 XML Web 服务。
服务器中任何不与其他应用 ......

asp.net中基于Form验证的角色授权验证

以下类容为转载,但是不知道是什么原因,经本人测试这个方法有一个bug,按照以下类容所设计的角色验证不能成功。Application_AuthorizeRequest事件改为Application_AuthenticateRequest事件才能实现。
Asp.net的身份验证有有三种,分别是"Windows | Forms | Passport",其中又以Forms验证用的最多,也最灵活。
Forms 验证 ......

asp.net常有小方法整理

  =================================<1>页面控制  ======================================
 <script type ="text/javascript"  src="../js/Calendar.js"charset ="gb2312"></script>
  <input ID="Text1" type="text" runat="server" onfocus="calendar()"/>
<!- ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号