Sunday, 14 December 2014

Uploading image in database and store in folder

  • Today I will show you that how to Upload Image in web application in ASP.NET to Use Visual Studio 2008 OR 2012.
  • Create table 'photo' in database. Field name:- images, img_name. 
  • We can create many tables in one database.
  • First We required some control like that textbox, fileupload, and button. And you have to make new folder in your web application
  • Now we take two namespace.
    using System.Data.SqlClient; //use this in namespace in both version.



    using System.Data; //not requerd to use this namespace in Visual Studo 2008.
Now in the class we write the connection object and other objects for Upload Image

    SqlConnection conn = new SqlConnection(@"path of the database/query string ");  //for create a connection.
    SqlCommand cmd; //interecting with the database means take the action in database like ad insert, update, delete. no required in log in program.
    SqlDataAdapter adp; // read the data from the database. ,always take this object wheneve establist the connection
     
    DataTable dt;


  • Now we write code in Upload button. 
  • If You want to only upload image, you write only this code.


    string str3 = "~/imgfolder/" + FileUpload3.FileName; // add folder name which is make in your webapplication


    FileUpload3.SaveAs(Server.MapPath(str3));

  • Or else Upload Image With add in database. You Write this code.
    conn.Open();    string str3 = "~/imges3/" + FileUpload3.FileName;
    FileUpload3.SaveAs(Server.MapPath(str3));    cmd = new SqlCommand("insert into dt values('" + str3 + "','" + TextBox1.text + "')", conn);
    cmd.ExecuteNonQuery();
    conn.Close();
 

Now Your Web application is ready to run.

GET FULL EXAMPLE

if You any Query in php or get Example of php click on :- PHP EXAMLE

No comments:

Post a Comment

Show image in data controls from the database

Hello...friends today I will show you that how to display image in data controls like that datalist,repeater. First We make data table. N...