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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted May 14, 2013, 1:41 PM
(
@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 patilPosted May 15, 2013, 1:58 AM
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