thank in advance...
ADD and Retrieve IMAGES from sql server 2008 in datalist c#
i need code to insert images in database and retrieve from database in to datalist .. so give the full code ...
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted May 14, 2013, 9:41 AM EDT
(
@name varchar(50),
@pic varchar(50)
)
AS
Insert into test values (@name,@pic)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ADD_Retrieve_IMAGES_datalist._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
namespace ADD_Retrieve_IMAGES_datalist
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string s1;
string path;
SqlConnection cnn = new SqlConnection();
SqlCommand com = new SqlCommand();
SqlDataAdapter sqlda;
DataTable dt;
protected void btn_insert_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.ContentLength > 0)
{
s1 = Path.GetFileName(FileUpload1.FileName);
path = Server.MapPath("images") + "/" + s1;
FileUpload1.SaveAs(path);
}
SqlConnection con = new SqlConnection(strConnString);
con.Open();
SqlCommand com = new SqlCommand("insert_test", con);
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.Parameters.AddWithValue("@name", txt_name.Text);
com.Parameters.AddWithValue("@pic", s1);
com.ExecuteNonQuery();
com.Dispose();
binddatalist();
con.Close();
clear();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
binddatalist();
}
}
private void clear()
{
txt_name.Text = "";
}
private void binddatalist()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
sqlda = new SqlDataAdapter("SELECT * FROM test ", con);
dt = new DataTable();
sqlda.Fill(dt);
sqlda.Dispose();
DataList1.DataSource = dt;
DataList1.DataBind();
con.Close();
}
}
}
sagar patil48 reputationPosted May 14, 2013, 9:58 PM EDT
Sir In data list i need Edit And Delete Buttons.. If i clicked edit button then all data fields should be display in their respective text box .. so give me code for that...
Thank U in advance