CS0117:'System.Data.OleDb.OleDbType'不包含'Image'的定义

时间:2013-01-08 05:57:40

标签: asp.net upload definition

帮助!

我正在做一个页面,它将在gridview中上传和显示图像。当我加载页面。

出现此错误:CS0117:'System.Data.OleDb.OleDbType'不包含'Image'的定义

 Compiler Error Message: CS0117: 'System.Data.OleDb.OleDbType' does not contain a definition for 'Image'

Source Error:


Line 26:  
Line 27:  OleDbParameter UploadedImage = new OleDbParameter
Line 28:               ("@Image", OleDbType.Image, imageSize.Length);
Line 29: 
Line 30:  UploadedImage.Value = imageSize;

Source File: c:\inetpub\wwwroot\logon\try.aspx    Line: 28 

这是我的完整代码:

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
<%@ Import Namespace= "System.Data.OleDb" %>


<script runat="server" type="text/c#">
protected void btnUpload_Click(object sender, EventArgs e)
{
    {
   byte[] imageSize = new byte
                 [FileUpload1.PostedFile.ContentLength];
  HttpPostedFile uploadedImage = FileUpload1.PostedFile;
  uploadedImage.InputStream.Read
     (imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
 // Create SQL Connection 
  OleDbConnection con = new OleDbConnection();
  con.ConnectionString = ConfigurationManager.ConnectionStrings["recordsConnectionString"].ConnectionString;
 // Create SQL Command 
 OleDbCommand cmd = new OleDbCommand();
 cmd.CommandText = "INSERT INTO PendingRecords(Image)" +
                   " VALUES (@Image)";
 cmd.CommandType = CommandType.Text;
 cmd.Connection = con;

 OleDbParameter UploadedImage = new OleDbParameter
              ("@Image", OleDbType.Image, imageSize.Length);

 UploadedImage.Value = imageSize;
 cmd.Parameters.Add(UploadedImage);
 con.Open();
 int result = cmd.ExecuteNonQuery();
 con.Close();
 if (result > 0)
 lblMessage.Text = "File Uploaded";
 GridView1.DataSource = SqlDataSource1;
 GridView1.DataBind();
 }
}
</script>

<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server"/>
<asp:Label ID="lblMessage" runat="server">
</asp:Label>
<asp:Button ID="btnUpload" runat="server" 
            OnClick="btnUpload_Click" Text="Upload"/>
</div>
<asp:GridView runat="server" id="GridView1" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="ID">
    <Columns>
        <asp:boundfield DataField="ID" HeaderText="ID" ReadOnly="True" InsertVisible="False" SortExpression="ID">
        </asp:boundfield>
        <asp:boundfield DataField="Image" HeaderText="Image" SortExpression="Image">
        </asp:boundfield>
    </Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" id="SqlDataSource1" ProviderName="<%$ ConnectionStrings:recordsConnectionString.ProviderName %>" ConnectionString="<%$ ConnectionStrings:recordsConnectionString %>" SelectCommand="SELECT * FROM [PendingRecords]">
</asp:SqlDataSource>
</form>

请帮忙! :)

1 个答案:

答案 0 :(得分:0)

线程关闭:)我刚解决了。我将OleDbType.Image更改为OleDbType.LongVarBinary。谢谢大家!