i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
insert image in database ,via image control (doesnot use fileupload control) in asp.n
11-24-2010, 07:32 PM (This post was last modified: 11-24-2010 08:09 PM by dn2010.)
Post: #1
Not Solved insert image in database ,via image control (doesnot use fileupload control) in asp.n
hi friends,

how to insert image in database ,via image control (doesnot use fileupload control). in asp.net using sql server.

please give the code.


thanks.



Thanks & Regards,
Quote
11-24-2010, 07:38 PM
Post: #2
Not Solved RE: how to insert image in database ,via image control (doesnot use fileupload control)
are you talking about windows application or web??
and is image control already have any assigned image?
please explain your scenario a little because i am confuse how you want to upload an image using image control.

[Image: 2604595733.png]
Quote
11-24-2010, 08:08 PM
Post: #3
Not Solved RE: how to insert image in database ,via image control (doesnot use fileupload control)
This is a web application,

if i click datalist image to image control,


i want to insert code for image control (does not use fileupload control).

please give the code for it.


thanks.

Thanks & Regards,
Quote
11-25-2010, 08:15 AM
Post: #4
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
if i click datalist image to image control,

Visible image to insert in database
i want to insert code for image control (does not use fileupload control) in asp.net.

protected void btnlogo_Click(object sender, EventArgs e)
{
OpenConnection(con);
cmd.Connection = con;
cmd.CommandText = "insert into erlogo1 values('" + txtdate.Text + "','" + txterid.Text + "','" + lblname.Text + "','" + Image1.ImageUrl.ToString() + "')";
Response.Write("<script>alert('Inserted Successfully')</script>");
cmd.ExecuteNonQuery();
Response.Redirect("home.aspx");
con.Close();


please give the code for it.

thanks.

Thanks & Regards,
Quote
11-25-2010, 08:39 AM
Post: #5
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
you can not redirect the page before closing the connection

Replace this
Code:
Response.Redirect("home.aspx");
con.Close();

with
Code:
con.Close();
Response.Redirect("home.aspx");

And also tell me what is error in your above code?

[Image: 2604595733.png]
Quote
11-25-2010, 08:43 AM (This post was last modified: 11-25-2010 08:45 AM by dn2010.)
Post: #6
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
thanks,

but my problem is

how to store shown image in image control

cmd.CommandText = "insert into erlogo1 values('" + Image1.ImageUrl.ToString() + "')";

protected void btnlogo_Click(object sender, EventArgs e)
{
OpenConnection(con);
cmd.Connection = con;
cmd.CommandText = "insert into erlogo1 values('" + txtdate.Text + "','" + txterid.Text + "','" + lblname.Text + "','" + Image1.ImageUrl.ToString() + "')";
Response.Write("<script>alert('Inserted Successfully')</script>");
cmd.ExecuteNonQuery();

con.Close();
Response.Redirect("home.aspx");
}

Thanks & Regards,
Quote
11-25-2010, 08:59 AM
Post: #7
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
you have already attached the code in your previous post, can you attach the database too?
because i want to see how it is currently running

[Image: 2604595733.png]
Quote
11-25-2010, 10:00 AM
Post: #8
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
Hi,
yes you can insert image in db first tell me one thing you want to store image url i.e. image path or image itself in db.

if you want to store image itself then please share ur db structure bcoz it requires certain changes in db.

Please give reputation if my answer/post is useful for you
Best Regards
Arti Gupta
Quote
11-25-2010, 10:01 AM
Post: #9
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
Hi dn2010,

if you can have data list then you have to find image control from the datalist please see below cod to find the image control.
Code:
foreach (DataListItem ARecord in dlArecord.Items)
{                
     ImageButton imgbutton= (ImageButton)ARecord.FindControl("imgButton");
}
and retrieve image path from control and store image path in database, if you want to store image then take the image from control path and store in database.

Thanks Regards
Shafiur Rahman
http://www.createsoftweb.com
Quote
11-25-2010, 09:15 PM (This post was last modified: 11-27-2010 07:33 PM by dn2010.)
Post: #10
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
thanks.

Thanks & Regards,
Quote
11-26-2010, 11:33 AM
Post: #11
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
your work is good...and better to use handler file in inserting and retrieving of images..any way i modified your code its working fine now...

the problem is so simple on buttondisplayimage,,just paste this code in that then execute...



protected void Btn_DisplayImage_Click(object sender, ImageClickEventArgs e)
{

//ViewState["InsertedURL"] = strImage;
string strImage = ((ImageButton)sender).CommandName;
//assign this image url in image control

Image1.ImageUrl = strImage;
string [] z = strImage.Split('=');

string y = z[1].ToString();

int id = int.Parse(y);


OpenConnection(con);
cmd.Connection = con;

cmd.CommandText = "SELECT * from reg where sid='"+id+"'";
dr = cmd.ExecuteReader();
while (dr.Read())
{
txtname.Text = dr[2].ToString();
txtrid.Text = dr[1].ToString();

}


con.Close();

}



replace above code in ur file..then njoyyyy.....


Rate the answer if your problem solved..

“A mind stretched by a new idea can never go back to its original dimension.”

Quote
11-26-2010, 11:34 AM (This post was last modified: 11-26-2010 11:35 AM by praveen.)
Post: #12
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
if you still face any problem let me know,so that i will send your project file..

“A mind stretched by a new idea can never go back to its original dimension.”

Quote
11-26-2010, 03:28 PM (This post was last modified: 11-26-2010 07:49 PM by dn2010.)
Post: #13
Not Solved RE: insert image in database ,via image control (doesnot use fileupload control) in asp.n
thanks for your response,

but , how to insert date,rid,Name,imgData(selected image from IMAGE CONTROL),imgType,imgLength in database.

and

how to retrieve the saved images & details in datalist / gridview.

protected void btnvote_Click(object sender, EventArgs e)
{
FileInfo fInfo = new FileInfo(Server.MapPath(imgbtn.ImageUrl.ToString()));
FileStream fs = new FileStream(Server.MapPath(imgbtn.ImageUrl.ToString()), FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] imgbytes = br.ReadBytes((int)fInfo.Length);

OpenConnection(con);
cmd.Connection = con;

cmd.CommandText = "INSERT INTO vote (Name,imgData) Values(@Name,@imgData)";// ('" + "suresh" + "','" + imgbytes + "')";
cmd.Parameters.AddWithValue("@Name", txtname.Text.Trim());
cmd.Parameters.AddWithValue("@imgData",(object)imgbytes);


cmd.ExecuteNonQuery();
con.Close();
}

please give the code.

thanks.

Thanks & Regards,
Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Web Service to Find Similar Image sharath 1 3,346 11-27-2015 12:02 PM
Last Post: nisar87
  how to read text from image in asp.net.? abhishekagrwl25 3 1,576 11-26-2015 03:26 AM
Last Post: wubuer
  converting pdf to image in c# ? xpert 3 5,078 08-06-2014 08:03 AM
Last Post: alxe_2014
  How to use this control in windows application. Jayakumar 2 1,155 05-20-2014 08:43 AM
Last Post: agileinfoways
  how to upload an image in vb.net Al-Kathur 5 3,409 04-24-2014 08:56 AM
Last Post: hongdida



User(s) browsing this thread: 1 Guest(s)