Click here to Skip to main content
15,894,294 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have created a website and I have to insert the customer record and image insert and image file path name
 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");
            SqlConnection con = new SqlConnection();
            con.ConnectionString = @"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=SSPI";
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "photoset";
                cmd.CommandType = CommandType.StoredProcedure;
                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.Connection = con;
                con.Open();
                cmd.ExecuteNonQuery();
            }
            finally
            {
                connection.Close();
            }
        }
    }
}

                          My Error  all record are insert but file name not insert how to change
Posted
Updated 7-Apr-11 21:03pm
v8
Comments
Dalek Dave 7-Apr-11 5:15am    
Edited for Grammar and Readability.

hope this solves,

http://stackoverflow.com/questions/5429162/inserting-an-image-and-thenfilepath-to-the-database[^]

Thanks,
www.codecollege.net | www.InterviewsGuru.com | www.chitraguptan.com | www.thekumbakonam.com
 
Share this answer
 
v2
Comments
kannan 2 7-Apr-11 2:10am    
How to correct the error
Dalek Dave 7-Apr-11 5:15am    
Good Link
You might want to change the type of variable filename. filename is a byte array.
You are trying to access a method called "GetName" that does not exist in arrays - hence this error.
 
Share this answer
 
Comments
kannan 2 7-Apr-11 1:32am    
how to correct i am beginer can you post the code

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