Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
4.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
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)
       {
        // Create a byte[] from the input file
        int len = flbload.PostedFile.ContentLength;
        byte[] pic = new byte[len];
        flbload.PostedFile.InputStream.Read(pic, 0, len);
        // Insert the image and comment into the database
        SqlConnection connection = new SqlConnection(@"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.Image).Value = pic;
            SqlParameter Src = new SqlParameter("@FilePath", SqlDbType.VarChar, 450);
            Src.Value = flbload.FileName;
            cmd.Parameters.Add(Src);
            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
My error page is run but image is stored and file name not stored first five record not insert how to correct
Posted
Updated 7-Apr-11 1:39am
v5
Comments
kannan 2 6-Apr-11 4:42am    
i want image file pat store how to change in my code

your are storing myImagePathValue that is Byte[] to varcharChar Column of the Database SystemUrl you need to convert that value either into string or Byte before storing it into the Database because you need to match that value with your database table Column DataType which is SystemUrl varchar
 
Share this answer
 
Comments
vimal22 2 4-Apr-11 1:42am    
thank you but error is Failed to convert parameter value from a Byte[] to a String.
Try this before storing or retrieving it from database

Converting a byte array to a string

C#
byte[]bLine = new byte[...];
// Fill with data bLine = ... 
 System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); 
string str = enc.GetString(bLine);


Converting a string to a bytearray

C#
string sStr = "whatever"
 System.Text.ASCIIEncoding  enc=new System.Text.ASCIIEncoding();
 byte []bArray = enc.GetBytes(sStr);
 
Share this answer
 
v2
Comments
vimal22 2 4-Apr-11 2:14am    
sorry i'm beginner please edit in code
vimal22 2 4-Apr-11 2:16am    
but Error 1 A local variable named 'enc' is already defined in this scope
Mahendra.p25 4-Apr-11 2:30am    
you can take two variable enc for storing and enc1 for retrieving whatever name you want.
vimal22 2 4-Apr-11 2:42am    
i edit code but error Failed to convert parameter value from a Byte[] to a String.

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