ヘルプ!
グリッドビューで画像をアップロードして表示するページを作成しています。ページをロードするとき。
このエラーが表示されました: 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>
助けてください!:)