高分求asp.net上传图片到Oracle数据库 已经在SqlServer测试上传成功,但上传到Oracle数据库弄不明白,请高手帮忙。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://dotnet.aspx.cc/ShowDetail.aspx?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506基本和Oracle也是一样的. 我看了你提供的网页,在Sql Server2000里,我也上传成功了,和你提供网页里面实现是一样的,但在Oracle数据库中就不行。 如下代码写入数据库//上传if(myFile.ContentLength != 0){ try { //将上传文件读取到数组里面 System.IO.Stream mystream = myFile.InputStream; byte[] Buffer = new byte[myFile.ContentLength]; mystream.Read(Buffer,0,myFile.ContentLength); //打开数据库 OracleConnection cn = new OracleConnection(ConfigurationSettings.AppSettings["sysDSN"]); cn.Open(); //用参数方式写入数据库 OracleCommand myComm = cn.CreateCommand(); string sql = "insert into tmp(tmp_id,tmp_blob) values(tmp_seq.nextval,:tmp_blob)"; myComm.CommandText = sql; myComm.Parameters.Add(":tmp_blob",OracleType.Blob,Buffer.Length).Value = Buffer; myComm.ExecuteNonQuery(); } catch { //此处可加错误显示 } finally { cn.Close(); }} 通过.NET上传图象(这是SQL SERVER数据库,楼主修改一下)作者:Chris Khoo 翻译:tigerwen01 以前,通过ASP上传图象(图象的大小、类型都受到限制)一般都是要借助外部组件来完成,.NET的出现,使这一工作变得非常容易并且可以随便的使用Bitmap和Image类型。在这个指导思想下,我将按照以下步骤(在你要上传图象文件上)创建一个简单的WEB窗体,该窗体将判断上传的文件是否是JPEG文件、判断该文件是否存在(必要时你可以重命名)。1、 创建一个新Web 应用程序项目;2、 打开Web 窗体;3、 在窗体上面添加一个HTML表单,并把它转换成服务器控件。在这个例子里,该文件将命名为filUpload;(把HTML转换成服务器控件的方法是,在它的上面右击鼠标然后选择Run As Server Control)4、 切换到HTML view并添加/更改FORM标签的enctype属性为multipart/form-data。如:enctype="multipart/form-data"。5、 在Web窗体上添加一个BUTTON并命名为btnUpload。6、 向Web应用程序添加一个folder called /images。7、 在窗体上添加一个Web Form Image并命名为imgPicture,设置宽度和高度分别为160和120。8、 添加一个Label控件并命名为lblOutput。显示当在上传的过程中发生的任何错误。9、 给按钮btnUpload的单击事件添加如下代码:(如果你想分析以下代码的细节,你可以把下面的代码复制粘贴到VS.NET IDE集成开发环境。)1. private void btnUpload_Click(object sender, System.EventArgs e)2. {3. // Initialize variables4. string sSavePath;5. string sThumbExtension;6. int intThumbWidth;7. int intThumbHeight;8. 9. // Set constant values10. sSavePath = "images/";11. sThumbExtension = "_thumb";12. intThumbWidth = 160;13. intThumbHeight = 120;14. 15. // If file field isn’t empty16. if (filUpload.PostedFile != null)17. {18. // Check file size (mustn’t be 0)19. HttpPostedFile myFile = filUpload.PostedFile;20. int nFileLen = myFile.ContentLength;21. if (nFileLen == 0)22. {23. lblOutput.Text = "No file was uploaded.";24. return;25. }26. 27. // Check file extension (must be JPG)28. if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")29. {30. lblOutput.Text = "The file must have an extension of JPG";31. return;32. }33. 34. // Read file into a data stream35. byte[] myData = new Byte[nFileLen];36. myFile.InputStream.Read(myData,0,nFileLen);37. 38. // Make sure a duplicate file doesn’t exist. If it does, keep on appending an 39. // incremental numeric until it is unique40. string sFilename = System.IO.Path.GetFileName(myFile.FileName);41. int file_append = 0;42. while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))43. {44. file_append++;45. sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)46. + file_append.ToString() + ".jpg";47. }48. 49. // Save the stream to disk50. System.IO.FileStream newFile51. = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename), 52. System.IO.FileMode.Create);53. newFile.Write(myData,0, myData.Length);54. newFile.Close();55. 56. // Check whether the file is really a JPEG by opening it57. System.Drawing.Image.GetThumbnailImageAbort myCallBack = 58. new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);59. Bitmap myBitmap;60. try61. {62. myBitmap = new Bitmap(Server.MapPath(sSavePath + sFilename));63. 64. // If jpg file is a jpeg, create a thumbnail filename that is unique.65. file_append = 0;66. string sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)67. + sThumbExtension + ".jpg";68. while (System.IO.File.Exists(Server.MapPath(sSavePath + sThumbFile)))69. {70. file_append++;71. sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + 72. file_append.ToString() + sThumbExtension + ".jpg";73. }74. 75. // Save thumbnail and output it onto the webpage76. System.Drawing.Image myThumbnail77. = myBitmap.GetThumbnailImage(intThumbWidth, 78. intThumbHeight, myCallBack, IntPtr.Zero);79. myThumbnail.Save (Server.MapPath(sSavePath + sThumbFile));80. imgPicture.ImageUrl = sSavePath + sThumbFile;81. 82. // Displaying success information83. lblOutput.Text = "File uploaded successfully!";84. 85. // Destroy objects86. myThumbnail.Dispose();87. myBitmap.Dispose();88. }89. catch (ArgumentException errArgument)90. {91. // The file wasn't a valid jpg file92. lblOutput.Text = "The file wasn't a valid jpg file.";93. System.IO.File.Delete(Server.MapPath(sSavePath + sFilename));94. }95. }96. }97. 98. public bool ThumbnailCallback()99. {100. return false;} 10.运行以上创建的 Web页(webpage),并分别使用JPG文件和其他类型的文件来测试错误检查(error-checking)机制。 http://community.csdn.net/Expert/topic/3548/3548658.xml?temp=.3258173 一、图像上传至数据库为了将图片存入数据库,我们有必要将数据库结构首先提出来,在保存图像的数据表中,我们针对图片,有一个专门的字段ImageDescription用来标明图像的相关信息,这样处理大量图像的时候就能通过这些简单的描述而区分它们;另外,ImageID字段用来作为图像唯一标示,Image字段用来存储图像信息;ContentType用来说明图像的ContentType类型;ByteSize用来保存图像的大小信息。下面是建表的SQL语句。CREATE TABLE [dbo].[Images] ([ImageID] [int] IDENTITY (1, 1) NOT NULL ,[Image] [image] NULL ,[ContentType] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[ImageDescription] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[ByteSize] [int] NULL) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]现在,我们来看数据图像上传的一个简单界面,在这里,用户选择一个图片,点击上传按钮就直接将图片保存到了数据库。<%@ Page Inherits="UploadSample.Main" SRC="Upload.cs"%><HTML><BODY><FORM ENCTYPE="multipart/form-data" RUNAT="server" ID="Form1"><h1>试验:<FONT COLOR="BLUE">System.Data.OleDb</FONT></h1><TABLE RUNAT="server" WIDTH="700" ALIGN="left" ID="Table1"><TR><TD><B>图像文件:</B></TD><TD><INPUT TYPE="file" ID="UP_FILE" RUNAT="server" STYLE="Width:320" ACCEPT="text/*" NAME="UP_FILE"></TD></TR><TR><TD><b>文件描述:</b></TD><TD><asp:TextBox RUNAT="server" WIDTH="239" ID="txtDescription" MAINTAINSTATE="false" /></TD></TR><TR><TD><asp:Label RUNAT="server" ID="txtMessage" FORECOLOR="red" MAINTAINSTATE="false" /></TD><TD><asp:Button RUNAT="server" WIDTH="239" ONCLICK="Button_Submit" TEXT="上传" /></TD></TR></TABLE></FORM></BODY></HTML>在以上的代码中,我们需要注意,在页面表单部分,注意加入:ENCTYPE="multipart/form-data",这与一般的表单不同;另外,以下代码用来实现选择文件的输入框:<INPUT TYPE="file" ID="UP_FILE" RUNAT="server" STYLE="Width:320" ACCEPT="text/*" NAME="UP_FILE">。 在以上数据提交界面,我们并没有看到任何对于数据库的处理,这就是ASP.NET编程的好处之一,这里使用了Code Behind技术,就是将一些功能模块设计成为一个类,在这个类中实现需要的功能,我们可以看到,页面代码开头的代码:<%@ Page Inherits="UploadSample.Main" SRC="Upload.cs"%>就是继承了上传图像的类,所有我们上传图像需要的处理就在这里实现。该类的源文件如下:namespace UploadSample {public class Main : System.Web.UI.Page {protected System.Web.UI.HtmlControls.HtmlInputFile UP_FILE;protected System.Web.UI.WebControls.TextBox txtDescription;protected System.Web.UI.WebControls.Label txtMessage;protected System.Int32 FileLength = 0;protected void Button_Submit(System.Object sender, System.EventArgs e) {System.Web.HttpPostedFile UpFile = UP_FILE.PostedFile;FileLength = UpFile.ContentLength;try {if (FileLength == 0) {txtMessage.Text = "<b>*请选择上传的文件</b>";} else {System.Byte[] FileByteArray = new System.Byte[FileLength];System.IO.Stream StreamObject = UpFile.InputStream;StreamObject.Read(FileByteArray,0,FileLength);System.Data.OleDb.OleDbConnection Con = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" +"Integrated Security=SSPI;Initial Catalog=northwind");System.String SqlCmd = "INSERT INTO Images (Image, ContentType, ImageDescription, ByteSize) VALUES (?, ?, ?, ?)";System.Data.OleDb.OleDbCommand OleDbCmdObj = new System.Data.OleDb.OleDbCommand(SqlCmd, Con);OleDbCmdObj.Parameters.Add("@Image", System.Data.OleDb.OleDbType.Binary, FileLength).Value = FileByteArray;OleDbCmdObj.Parameters.Add("@ContentType", System.Data.OleDb.OleDbType.VarChar,50).Value = UpFile.ContentType;OleDbCmdObj.Parameters.Add("@ImageDescription", System.Data.OleDb.OleDbType.VarChar,100).Value = txtDescription.Text;OleDbCmdObj.Parameters.Add("@ByteSize", System.Data.OleDb.OleDbType.VarChar,100).Value = UpFile.ContentLength;Con.Open();OleDbCmdObj.ExecuteNonQuery();Con.Close();txtMessage.Text = "<p><b>* 图片上传成功!</b>";}} catch (System.Exception ex) {txtMessage.Text = ex.Message.ToString();}}}}以上的代码比较简单,我们现在只来仔细研究数据上传到数据库的代码:System.Data.OleDb.OleDbConnection Con = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" +"Integrated Security=SSPI;Initial Catalog=northwind");System.String SqlCmd = "INSERT INTO Images (Image, ContentType, ImageDescription, ByteSize) VALUES (?, ?, ?, ?)";System.Data.OleDb.OleDbCommand OleDbCmdObj = new System.Data.OleDb.OleDbCommand(SqlCmd, Con);OleDbCmdObj.Parameters.Add("@Image", System.Data.OleDb.OleDbType.Binary, FileLength).Value = FileByteArray;OleDbCmdObj.Parameters.Add("@ContentType", System.Data.OleDb.OleDbType.VarChar,50).Value = UpFile.ContentType;OleDbCmdObj.Parameters.Add("@ImageDescription", System.Data.OleDb.OleDbType.VarChar,100).Value = txtDescription.Text;OleDbCmdObj.Parameters.Add("@ByteSize", System.Data.OleDb.OleDbType.VarChar,100).Value = UpFile.ContentLength;Con.Open();OleDbCmdObj.ExecuteNonQuery();Con.Close();以上代码中,首先建立了一个到SQL Server的数据库链接;然后,建立了一个数据插入的OleDbCommand,注意一点,在建立这个OleDbCommand的时候,我们这里没有使用“@”标志而是使用“?”来代替输入变量。另外,对于SQL.NET而言,因为其提供了一个SqlDbType.Image的数据类型,该类型对数据限制大小为:2,147,483,647,相信绝大部分用户不会上传这样大的文件,因此,可以直接使用以下语句:MySqlCmd.Parameters.Add("@Image", SqlDbType.Image).Value = FileByteArray而在OleDb.NET中,是没有这样类型定义的,我们只能使用OleDbType.Binary类型,这样,对于上传的限制就是8000字节,如果上传文件大于该限制,就会出错,因此,在使用OleDb.NET的时候,我们就必须很清楚的设置上传文件的大小,代码如下:OleDbCmdObj.Parameters.Add("@Image", System.Data.OleDb.OleDbType.Binary, FileLength).Value = FileByteArray 谢谢各位,问题已经通过其它途径解决,各位的资料都是应用于Sql Server的解决方法,在Oracle中不可用。 页面刷新 Page_Load事件的问题 请教个ASP与JS交互的问题(JS调用后台带参数的函数) C# asp.net中怎样动态设置Image控件的ImageUrl属性为远程FTP服务器地址。 各位大锅大姐,在线等! asp.net连接oracle数据库出现乱码问题(100分坐等解答) 问个ASP。NET控制层的问题 初学者求指教~关于更改数据库状态的方式 史上比较难的问题之一 菜鸟问题,关于Session ASP.net记录应用程序级的变量应该放在Global.asax中吗? 各位高手,100分求限制同一用户重复登陆的高效解决方案 asp.net组件问题
写入数据库//上传
if(myFile.ContentLength != 0)
{
try
{
//将上传文件读取到数组里面
System.IO.Stream mystream = myFile.InputStream;
byte[] Buffer = new byte[myFile.ContentLength];
mystream.Read(Buffer,0,myFile.ContentLength); //打开数据库
OracleConnection cn = new OracleConnection(ConfigurationSettings.AppSettings["sysDSN"]);
cn.Open(); //用参数方式写入数据库
OracleCommand myComm = cn.CreateCommand();
string sql = "insert into tmp(tmp_id,tmp_blob) values(tmp_seq.nextval,:tmp_blob)";
myComm.CommandText = sql;
myComm.Parameters.Add(":tmp_blob",OracleType.Blob,Buffer.Length).Value = Buffer;
myComm.ExecuteNonQuery();
}
catch
{
//此处可加错误显示
}
finally
{
cn.Close();
}
}
2. {
3. // Initialize variables
4. string sSavePath;
5. string sThumbExtension;
6. int intThumbWidth;
7. int intThumbHeight;
8.
9. // Set constant values
10. sSavePath = "images/";
11. sThumbExtension = "_thumb";
12. intThumbWidth = 160;
13. intThumbHeight = 120;
14.
15. // If file field isn’t empty
16. if (filUpload.PostedFile != null)
17. {
18. // Check file size (mustn’t be 0)
19. HttpPostedFile myFile = filUpload.PostedFile;
20. int nFileLen = myFile.ContentLength;
21. if (nFileLen == 0)
22. {
23. lblOutput.Text = "No file was uploaded.";
24. return;
25. }
26.
27. // Check file extension (must be JPG)
28. if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
29. {
30. lblOutput.Text = "The file must have an extension of JPG";
31. return;
32. }
33.
34. // Read file into a data stream
35. byte[] myData = new Byte[nFileLen];
36. myFile.InputStream.Read(myData,0,nFileLen);
37.
38. // Make sure a duplicate file doesn’t exist. If it does, keep on appending an
39. // incremental numeric until it is unique
40. string sFilename = System.IO.Path.GetFileName(myFile.FileName);
41. int file_append = 0;
42. while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
43. {
44. file_append++;
45. sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
46. + file_append.ToString() + ".jpg";
47. }
48.
49. // Save the stream to disk
50. System.IO.FileStream newFile
51. = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename),
52. System.IO.FileMode.Create);
53. newFile.Write(myData,0, myData.Length);
54. newFile.Close();
55.
56. // Check whether the file is really a JPEG by opening it
57. System.Drawing.Image.GetThumbnailImageAbort myCallBack =
58. new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
59. Bitmap myBitmap;
60. try
61. {
62. myBitmap = new Bitmap(Server.MapPath(sSavePath + sFilename));
63.
64. // If jpg file is a jpeg, create a thumbnail filename that is unique.
65. file_append = 0;
66. string sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
67. + sThumbExtension + ".jpg";
68. while (System.IO.File.Exists(Server.MapPath(sSavePath + sThumbFile)))
69. {
70. file_append++;
71. sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) +
72. file_append.ToString() + sThumbExtension + ".jpg";
73. }
74.
75. // Save thumbnail and output it onto the webpage
76. System.Drawing.Image myThumbnail
77. = myBitmap.GetThumbnailImage(intThumbWidth,
78. intThumbHeight, myCallBack, IntPtr.Zero);
79. myThumbnail.Save (Server.MapPath(sSavePath + sThumbFile));
80. imgPicture.ImageUrl = sSavePath + sThumbFile;
81.
82. // Displaying success information
83. lblOutput.Text = "File uploaded successfully!";
84.
85. // Destroy objects
86. myThumbnail.Dispose();
87. myBitmap.Dispose();
88. }
89. catch (ArgumentException errArgument)
90. {
91. // The file wasn't a valid jpg file
92. lblOutput.Text = "The file wasn't a valid jpg file.";
93. System.IO.File.Delete(Server.MapPath(sSavePath + sFilename));
94. }
95. }
96. }
97.
98. public bool ThumbnailCallback()
99. {
100. return false;
} 10.运行以上创建的 Web页(webpage),并分别使用JPG文件和其他类型的文件来测试错误检查(error-checking)机制。
CREATE TABLE [dbo].[Images] ([ImageID] [int] IDENTITY (1, 1) NOT NULL ,[Image] [image] NULL ,[ContentType] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[ImageDescription] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[ByteSize] [int] NULL) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
现在,我们来看数据图像上传的一个简单界面,在这里,用户选择一个图片,点击上传按钮就直接将图片保存到了数据库。
<%@ Page Inherits="UploadSample.Main" SRC="Upload.cs"%><HTML><BODY><FORM ENCTYPE="multipart/form-data" RUNAT="server" ID="Form1"><h1>试验:<FONT COLOR="BLUE">System.Data.OleDb</FONT></h1><TABLE RUNAT="server" WIDTH="700" ALIGN="left" ID="Table1"><TR><TD><B>图像文件:</B></TD><TD><INPUT TYPE="file" ID="UP_FILE" RUNAT="server" STYLE="Width:320" ACCEPT="text/*" NAME="UP_FILE"></TD></TR><TR><TD><b>文件描述:</b></TD><TD><asp:TextBox RUNAT="server" WIDTH="239" ID="txtDescription" MAINTAINSTATE="false" /></TD></TR><TR><TD><asp:Label RUNAT="server" ID="txtMessage" FORECOLOR="red" MAINTAINSTATE="false" /></TD><TD><asp:Button RUNAT="server" WIDTH="239" ONCLICK="Button_Submit" TEXT="上传" /></TD></TR></TABLE></FORM></BODY></HTML>
在以上的代码中,我们需要注意,在页面表单部分,注意加入:ENCTYPE="multipart/form-data",这与一般的表单不同;另外,以下代码用来实现选择文件的输入框:<INPUT TYPE="file" ID="UP_FILE" RUNAT="server" STYLE="Width:320" ACCEPT="text/*" NAME="UP_FILE">。
public class Main : System.Web.UI.Page {
protected System.Web.UI.HtmlControls.HtmlInputFile UP_FILE;protected System.Web.UI.WebControls.TextBox txtDescription;protected System.Web.UI.WebControls.Label txtMessage;protected System.Int32 FileLength = 0;
protected void Button_Submit(System.Object sender, System.EventArgs e) {System.Web.HttpPostedFile UpFile = UP_FILE.PostedFile;FileLength = UpFile.ContentLength;
try {
if (FileLength == 0) {
txtMessage.Text = "<b>*请选择上传的文件</b>";
} else {
System.Byte[] FileByteArray = new System.Byte[FileLength];System.IO.Stream StreamObject = UpFile.InputStream;StreamObject.Read(FileByteArray,0,FileLength);System.Data.OleDb.OleDbConnection Con = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" +"Integrated Security=SSPI;Initial Catalog=northwind");System.String SqlCmd = "INSERT INTO Images (Image, ContentType, ImageDescription, ByteSize) VALUES (?, ?, ?, ?)";System.Data.OleDb.OleDbCommand OleDbCmdObj = new System.Data.OleDb.OleDbCommand(SqlCmd, Con);OleDbCmdObj.Parameters.Add("@Image", System.Data.OleDb.OleDbType.Binary, FileLength).Value = FileByteArray;OleDbCmdObj.Parameters.Add("@ContentType", System.Data.OleDb.OleDbType.VarChar,50).Value = UpFile.ContentType;OleDbCmdObj.Parameters.Add("@ImageDescription", System.Data.OleDb.OleDbType.VarChar,100).Value = txtDescription.Text;OleDbCmdObj.Parameters.Add("@ByteSize", System.Data.OleDb.OleDbType.VarChar,100).Value = UpFile.ContentLength;Con.Open();OleDbCmdObj.ExecuteNonQuery();Con.Close();txtMessage.Text = "<p><b>* 图片上传成功!</b>";
}
} catch (System.Exception ex) {
txtMessage.Text = ex.Message.ToString();
}}}}
以上的代码比较简单,我们现在只来仔细研究数据上传到数据库的代码:System.Data.OleDb.OleDbConnection Con = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" +"Integrated Security=SSPI;Initial Catalog=northwind");System.String SqlCmd = "INSERT INTO Images (Image, ContentType, ImageDescription, ByteSize) VALUES (?, ?, ?, ?)";System.Data.OleDb.OleDbCommand OleDbCmdObj = new System.Data.OleDb.OleDbCommand(SqlCmd, Con);OleDbCmdObj.Parameters.Add("@Image", System.Data.OleDb.OleDbType.Binary, FileLength).Value = FileByteArray;OleDbCmdObj.Parameters.Add("@ContentType", System.Data.OleDb.OleDbType.VarChar,50).Value = UpFile.ContentType;OleDbCmdObj.Parameters.Add("@ImageDescription", System.Data.OleDb.OleDbType.VarChar,100).Value = txtDescription.Text;OleDbCmdObj.Parameters.Add("@ByteSize", System.Data.OleDb.OleDbType.VarChar,100).Value = UpFile.ContentLength;Con.Open();OleDbCmdObj.ExecuteNonQuery();Con.Close();
以上代码中,首先建立了一个到SQL Server的数据库链接;然后,建立了一个数据插入的OleDbCommand,注意一点,在建立这个OleDbCommand的时候,我们这里没有使用“@”标志而是使用“?”来代替输入变量。另外,对于SQL.NET而言,因为其提供了一个SqlDbType.Image的数据类型,该类型对数据限制大小为:2,147,483,647,相信绝大部分用户不会上传这样大的文件,因此,可以直接使用以下语句:MySqlCmd.Parameters.Add("@Image", SqlDbType.Image).Value = FileByteArray而在OleDb.NET中,是没有这样类型定义的,我们只能使用OleDbType.Binary类型,这样,对于上传的限制就是8000字节,如果上传文件大于该限制,就会出错,因此,在使用OleDb.NET的时候,我们就必须很清楚的设置上传文件的大小,代码如下:OleDbCmdObj.Parameters.Add("@Image", System.Data.OleDb.OleDbType.Binary, FileLength).Value = FileByteArray