0

グリッドビューからデータベース内の画像を取得して更新したいですか? お知らせ下さい

ザイヌル

4

2 に答える 2

0
 protected void btnSubmit_Click(object sender, EventArgs e)
{
//Get Filename from fileupload control
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
//Save images into Images folder
fileuploadimages.SaveAs(Server.MapPath("Images/"+filename));
//Getting dbconnection from web.config connectionstring
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
//Open the database connection
con.Open();
//Query to insert images path and name into database
SqlCommand cmd = new SqlCommand("Insert into ImagesPath(ImageName,ImagePath) values(@ImageName,@ImagePath)", con);
//Passing parameters to query
cmd.Parameters.AddWithValue("@ImageName", filename);
cmd.Parameters.AddWithValue("@ImagePath", "Images/" + filename);
cmd.ExecuteNonQuery();
//Close dbconnection
con.Close();
Response.Redirect("~/Default.aspx");
}

参照リンク:

http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html

于 2013-10-26T05:57:28.447 に答える
0

Try out in this way for edit and retrieve :

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ci_id" DataSourceID="SqlDataSource1">
            <Columns>
               <asp:TemplateField>
                   <EditItemTemplate>
                       <asp:FileUpload ID="FileUpload1" runat="server" /><asp:Button ID="Button1" runat="server" Text="Button" />
                   </EditItemTemplate>
                   <ItemTemplate>
                       <asp:Image ID="Image1" runat="server" />
                   </ItemTemplate>
               </asp:TemplateField>               
            </Columns>            
 </asp:GridView>  
于 2013-10-24T11:04:18.843 に答える