图片上传到数据库并显示(c+access)
ReadyGo!技术成就梦想
www.efish.cn
efish
2007-10-25 10:14:29
//上传文件:upload.aspx
<%@ page language="c#" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<%@ import namespace="system.io" %>
<script runat="server">
public void addperson(object sender, eventargs e)
{
int64 intimagesize;
string strimagetype;
stream imagestream ;
intimagesize = personimage.postedfile.contentlength;
strimagetype = personimage.postedfile.contenttype;
imagestream = personimage.postedfile.inputstream;
byte;
int intstatus= imagestream.read(imagecontent,0,personimage.postedfile.contentlength);
oledbconnection myconnection = new oledbconnection( "provider=microsoft.jet.oledb.4.0;data source=" + server.mappath("ps.mdb"));
oledbcommand mycommand = new oledbcommand("insert into manhua(img,biaoti,laiyuan,author,keyword,content) values(@img,@biaoti,@laiyuan,@author,@keyword,@content)", myconnection);
mycommand.parameters.add("@img",imagecontent);
mycommand.parameters.add("@biaoti",txtname.text);
mycommand.parameters.add("@laiyuan",textbox1.text);
mycommand.parameters.add("@author",textbox2.text);
mycommand.parameters.add("@keyword",textbox3.text);
mycommand.parameters.add("@content",textbox4.text);
try
{
myconnection.open();
mycommand.executenonquery();
myconnection.close();
//response.write("<font color="red">new person successfully added!</font>");
}
catch(oledbexception ex)
{
response.write("insert failed.error details are:" + ex.tostring());
}
txtname.text="";
}
</script>
<html>
<head>
<title>upload image to db!</title>
</head>
<body style="font: 10pt verdana">
<form enctype="multipart/form-data" runat="server">
<table align="center">
<tbody>
<tr>
<td>
<font size="2">标 题:</font>
<asp:textbox id="txtname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>
<font size="2">来 源:</font>
<asp:textbox id="textbox1" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>
<font size="2">作 者:</font>
<asp:textbox id="textbox2" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>
<font size="2">关键字:</font>
<asp:textbox id="textbox3" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>
<font size="2">图 片:</font>
<input id="personimage" type="file" runat="server" />
</td>
</tr>
<tr>
<td>
<font size="2">内 容:</font>
<asp:textbox id="textbox4" runat="server" height="76px" width="383px" textmode="multiline"></asp:textbox>
</td>
</tr>
<tr>
<td>
<asp:button id="button1" onclick="addperson" text="添加" runat="server" width="60"></asp:button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
//读出图片文件
<%@ page language="c#" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<script runat="server">
public void page_load(object sender, eventargs e)
{
if(!ispostback)
{
bindgrid();
}
}
private void bindgrid()
{
oledbconnection mycn = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" + server.mappath("ps.mdb"));
oledbcommand mycmd =new oledbcommand("select * from manhua",mycn);
mycmd.commandtype = commandtype.text;
<%@ page language="c#" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<%@ import namespace="system.io" %>
<script runat="server">
public void addperson(object sender, eventargs e)
{
int64 intimagesize;
string strimagetype;
stream imagestream ;
intimagesize = personimage.postedfile.contentlength;
strimagetype = personimage.postedfile.contenttype;
imagestream = personimage.postedfile.inputstream;
byte;
int intstatus= imagestream.read(imagecontent,0,personimage.postedfile.contentlength);
oledbconnection myconnection = new oledbconnection( "provider=microsoft.jet.oledb.4.0;data source=" + server.mappath("ps.mdb"));
oledbcommand mycommand = new oledbcommand("insert into manhua(img,biaoti,laiyuan,author,keyword,content) values(@img,@biaoti,@laiyuan,@author,@keyword,@content)", myconnection);
mycommand.parameters.add("@img",imagecontent);
mycommand.parameters.add("@biaoti",txtname.text);
mycommand.parameters.add("@laiyuan",textbox1.text);
mycommand.parameters.add("@author",textbox2.text);
mycommand.parameters.add("@keyword",textbox3.text);
mycommand.parameters.add("@content",textbox4.text);
try
{
myconnection.open();
mycommand.executenonquery();
myconnection.close();
//response.write("<font color="red">new person successfully added!</font>");
}
catch(oledbexception ex)
{
response.write("insert failed.error details are:" + ex.tostring());
}
txtname.text="";
}
</script>
<html>
<head>
<title>upload image to db!</title>
</head>
<body style="font: 10pt verdana">
<form enctype="multipart/form-data" runat="server">
<table align="center">
<tbody>
<tr>
<td>
<font size="2">标 题:</font>
<asp:textbox id="txtname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>
<font size="2">来 源:</font>
<asp:textbox id="textbox1" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>
<font size="2">作 者:</font>
<asp:textbox id="textbox2" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>
<font size="2">关键字:</font>
<asp:textbox id="textbox3" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>
<font size="2">图 片:</font>
<input id="personimage" type="file" runat="server" />
</td>
</tr>
<tr>
<td>
<font size="2">内 容:</font>
<asp:textbox id="textbox4" runat="server" height="76px" width="383px" textmode="multiline"></asp:textbox>
</td>
</tr>
<tr>
<td>
<asp:button id="button1" onclick="addperson" text="添加" runat="server" width="60"></asp:button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
//读出图片文件
<%@ page language="c#" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<script runat="server">
public void page_load(object sender, eventargs e)
{
if(!ispostback)
{
bindgrid();
}
}
private void bindgrid()
{
oledbconnection mycn = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" + server.mappath("ps.mdb"));
oledbcommand mycmd =new oledbcommand("select * from manhua",mycn);
mycmd.commandtype = commandtype.text;
-
相关文章
图片上传到数据库并显示(c+acce..
//上传文件:upload.aspx public void addperson(object sender, eventargs e) { int64 intimage..
图片上传到数据库并显示(c+acce..
//上传文件:upload.aspx public void addperson(object sender, eventargs e) { int64 intimage..
图片上传到数据库并显示(c+acce..
//上传文件:upload.aspx public void addperson(object sender, eventargs e) { int64 ..
图片上传到数据库并显示(c+acce..
//上传文件:upload.aspx public void addperson(object sender, eventargs e) { int64 ..
图片上传到数据库并显示(c+acce..
//上传文件:upload.aspx public void addperson(object sender, eventargs e) { int64 ..
图片上传到数据库并显示(c+acce..
//上传文件:upload.aspx
public void addperson(object sender, eventargs e)
{
..
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn
