Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm designing my web page i want store image location and then customer record i am doing photo studio management studio system image location not store...
namespace photoshops
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            onflbload(sender, e);
        }
        public void onflbload(object sender, EventArgs e)
        {
            string filename = Server.MapPath("~/photo") + FileUpload.PostedFile.FileName;
            FileUpload.PostedFile.SaveAs(filename);
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=SSPI";
               
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("insert into tblphotosettings "
                 + "(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values (@BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total)", connection);
                cmd.Parameters.Add("@BillNo", SqlDbType.NVarChar).Value = TextBox1.Text;
                cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value = TextBox2.Text;
                cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = TextBox3.Text;
                cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value = Rdbsdate.SelectedDate;
                cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar).Value = Rdbddate.SelectedDate;
                cmd.Parameters.Add("@Systemurl", SqlDbType.VarChar).Value = filename;
                cmd.Parameters.Add("@Numberofcopies", SqlDbType.NVarChar).Value = TextBox7.Text;
                cmd.Parameters.Add("@Amount", SqlDbType.NVarChar).Value = TextBox8.Text;
                cmd.Parameters.Add("@Total", SqlDbType.NVarChar).Value = TextBox9.Text;
                cmd.ExecuteNonQuery();
            }
            
            finally
            {
                connection.Close();
            }
        }
    }
}


My error
page is run .i have click the browser controle choose a file window open select the photo folder but path is in correct
Posted
Updated 4-Apr-11 20:43pm
v7

you have to change your Systemurl field to 'Binary'
 
Share this answer
 
Comments
vimal22 2 4-Apr-11 4:55am    
only i have store picture location(path)ex (D:divya/k.jpeg) and customer record.... change any code?
mukesh.mr03 4-Apr-11 4:58am    
Ok then there is no need to pass 'myImagePathOnDisk' to insert command. You just upload your file to a server folder, get the file path and pass to the insert command parameter.
vimal22 2 4-Apr-11 5:05am    
thank you.how do i because i am beginner
hi when you want to store only the image path then why you used the image stream.
just get the image path(absolute path) from the posted file and save the image in the temp folder(optional) and save the image path into the database.
suppose your image has path c:\picture\hen.jpeg the the absolute path becomes hen.jpeg and you can just store the absolute path and make use of it any where in your project.

Thanks.
Balwant
 
Share this answer
 
Comments
vimal22 2 4-Apr-11 5:17am    
Hionly i have store c:\picture\hen.jpeg.(i have use file upload control use. database store in image location) and customer details. how do i change in my code because i am beginner
public void onflbload(object sender, EventArgs e)
        {
            
      
string filename=Server.MapPath("~\YourUploadFolder")+FileUpload.PostedFile.FileName;
FileUpload.PostedFile.SaveAs(filename);
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=SSPI";
               
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("insert into tblphotosettings "
                 + "(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values (@BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total)", connection);
                cmd.Parameters.Add("@BillNo", SqlDbType.NVarChar).Value = TextBox1.Text;
                cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value = TextBox2.Text;
                cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = TextBox3.Text;
                cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value = Rdbsdate.SelectedDate;
                cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar).Value = Rdbddate.SelectedDate;
                cmd.Parameters.Add("@Systemurl", SqlDbType.VarChar).Value = filename;
                cmd.Parameters.Add("@Numberofcopies", SqlDbType.NVarChar).Value = TextBox7.Text;
                cmd.Parameters.Add("@Amount", SqlDbType.NVarChar).Value = TextBox8.Text;
                cmd.Parameters.Add("@Total", SqlDbType.NVarChar).Value = TextBox9.Text;
                cmd.ExecuteNonQuery();
            }
            
            finally
            {
                connection.Close();
            }
        }


Check whether the code works.
 
Share this answer
 
Comments
vimal22 2 4-Apr-11 5:26am    
thank you
but error is

Error 1 Unrecognized escape sequence C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\photoshops\photoshops\photosetting.aspx.cs 33 47 photoshops
vimal22 2 4-Apr-11 5:30am    
string filename=Server.MapPath("~\YourUploadFolder")+FileUpload.PostedFile.FileName


this line error.the error is ("~\YourUploadFolder"
mukesh.mr03 4-Apr-11 5:31am    
string filename=Server.MapPath("~/YourUploadFolder")+FileUpload.PostedFile.FileName
vimal22 2 4-Apr-11 5:45am    
The error is

Error 1 An object reference is required for the non-static field, method, or property 'System.Web.UI.WebControls.FileUpload.PostedFile.get'

Error 2 An object reference is required for the non-static field, method, or property 'System.Web.UI.WebControls.FileUpload.PostedFile.get' C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\photoshops\photoshops\photosetting.aspx.cs 33 13 photoshops
mukesh.mr03 4-Apr-11 5:47am    
can post the code now using or send the code file then i can check what is the actual problem.
You can store only path of Image in database like ~\foldername\image1.gif
the concat both string variable directoryname and image name then send it as parameter of command . when you want to retrive then u will get the Path of image from solution it assign to image control.it's use three variable and use it.

and you can store Image in Binary format of image in database convert image into 64bit then you can store it .but i First solution is very easy.
and
 
Share this answer
 
Comments
vimal22 2 5-Apr-11 3:05am    
thank you i am begineer can you post the code

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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