插入和上传图像 [英] Inserting and uploading image
本文介绍了插入和上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以向我发送代码,以便使用c#.net从sql检索上传的图像吗?
Hi,
can you send me a code for retrieving an uploading image from sql using c#.net?
推荐答案
^ ]将有所帮助您很快.
THIS[^] would help you quick.
只需使用google或查看以下链接:
在SQL Server中存储或保存图像 [ SQL数据库映像存储&简单的缩略图 [ ^ ]
Just use google or see these links:
Store or Save images in SQL Server[^]
SQL Database Image Storage & Easy Thumbnails[^]
在应用程序中创建一个名为Album
的文件夹 在按钮上单击,写此查询
make a folder in your application named as Album
on button click write this query
if (FileUpload1.HasFile)
{
string SFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
int fileAppent = 0;
while (File.Exists(Server.MapPath("~/Album/" + SFileName)))
{
fileAppent++;
SFileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName)
+ fileAppent.ToString() + Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();
}
path = Server.MapPath("~/Album/" + SFileName);
FileUpload1.PostedFile.SaveAs(path);
string ab = "~/Album/" + SFileName;
Sqlcommand cmd =新的Sqlcommand(插入表名(image)values(ab)",con);
con.Open();
cmd.ExecutenonQuety();
con.Close();
重新获取数据列表或gridview
我已经在数据列表中显示了
Sqlcommand cmd=new Sqlcommand ("insert into tablename (image)values(ab)",con);
con.Open();
cmd.ExecutenonQuety();
con.Close();
to reterive take datalist or gridview
I have shown in datalist
<asp:DataList ID="DataLstEmployee" Width="100%" runat="server"
Font-Names="Verdana" Font-Size="Small" ForeColor="#000099">
<ItemTemplate>
<asp:Image ID="Image1" Width="75%" Height="75%" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "image")%>'/>
</ItemTemplate>
</asp:DataList>
并在Gridview中
and in Gridview
<asp:GridView ID="GridView1" Runat="server"
DataSource='<%# GetData() %>' AutoGenerateColumns="False"
BorderWidth="1px" BackColor="White" CellPadding="3" BorderStyle="None"
BorderColor="#CCCCCC" Font-Names="Arial">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<PagerStyle ForeColor="#000066" HorizontalAlign="Left"
BackColor="White"></PagerStyle>
<HeaderStyle ForeColor="White" Font-Bold="True"
BackColor="#006699"></HeaderStyle>
<Columns>
<asp:ImageField DataImageUrlField="image"></asp:ImageField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True"
BackColor="#669999"></SelectedRowStyle>
<RowStyle ForeColor="#000066"></RowStyle>
</asp:GridView>
并从后面的代码中绑定此数据列表
and bind this datalist from code behind
这篇关于插入和上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文