Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all i have four fields in my screen like below
id
ename
date
image using fileupload control
so when i click on save button all field should enter in database

after that in second screen
i want images slide show withe the image we have inserted in database related to system date
below of that images marquee scrolling the "ename" of date indatabase related to sysdare should scroll
i want complete code
Posted
Comments
[no name] 1-Jul-15 7:54am    
If you want "complete code", then write it yourself or hire someone to write it for you. No one here is just going to write your code for you.
raviram123 10-Jul-15 0:35am    
ok i wil write by my own no problem complete code only links not to implement u
ok
Ambati Dilip 1-Jul-15 8:03am    
images are going to insert into tables use encode image into string and then decode when ever you want it. or use place your images in ftp server or use any images repository and use that web link into tables.
Nathan Minier 1-Jul-15 8:10am    
You can also insert them as BLOBS using more modern SqlServer.

Assume this is our table:
SQL
CREATE TABLE dbo.MyPictures
(
	Id INT IDENTITY(1,1) NOT NULL,
	Picture IMAGE NOT NULL,
    CONSTRAINT PK_MyPictures PRIMARY KEY CLUSTERED (Id)
);


This code will insert an image file into the database.
C#
string commandText = "INSERT INTO dbo.MyPictures (Picture) VALUES (@picture);";

byte[] fileBuffer = File.ReadAllBytes("MyPicture.jpg");

using (SqlConnection sqlConnection = new SqlConnection("data source=localhost;initial catalog=Scratch;integrated security=True;"))
using (SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection))
{
    sqlCommand.Parameters.AddWithValue("@picture", fileBuffer);

    sqlConnection.Open();
    sqlCommand.ExecuteNonQuery();
    sqlConnection.Close();
}


Make sure you read the MSDN documentation on using this data type. This is a fixed length field which means if the image is one byte or 100 bytes, both will use the same amount of storage. Also, I wasn't able to confirm this, but rumors have been that Microsoft is planning on dropping support of this data type in favor of the BINARY and VARBINARY.
ntext, text, and image (Transact-SQL)[^]
 
Share this answer
 
code on button click for insert

string _path, _fname;
if (FileUpload1.HasFile)
{
_fname = FileUpload1.FileName;
_path="~/uploads/"+_fname.ToString();
FileUpload1.SaveAs(Server.MapPath(_path));
string ins = "insert into tblname(picture)values('" + _path + "')";
SqlCommand cmd = new SqlCommand(ins, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}

for select
string sel = "select picture from tblname";
SqlDataAdapter da = new SqlDataAdapter(sel,conn);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Image1.ImageUrl = dt.Rows[0]["picture"].ToString();
}
 
Share this answer
 
Comments
raviram123 10-Jul-15 0:38am    
this wil insert file to folder and path to database but i want to insert image to database any way thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900