Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to store my resume data into the resume_data column defined as image type of sql table on the addbutton_click event in windows not in web.
Posted
Updated 14-Oct-12 23:40pm
v2
Comments
Vinod Satapara 15-Oct-12 9:09am    
Please provide more details. Do you want to save .doc or .docx file in sql table image type of column?
StackQ 16-Oct-12 7:51am    
both type,input file may be in (.doc or .docx)

private byte[] ResumeData;
public byte[] ResumeData_
{
    get { return ResumeData; }
    set { ResumeData = value; }
}

string Connstr=System.Configuration.ConfigurationManager.AppSettings["Connstr"].ToString();

public void Submit()
{

    SqlCommand Cmd = new SqlCommand();
    SqlConnection Conn = new SqlConnection(Connstr);
    Conn.Open();
    Cmd.Connection = Conn;
    Cmd.CommandType = CommandType.StoredProcedure;
    Cmd.CommandText = "SP_Insert_Joinee";

    Para1 = new SqlParameter();
    Para1.ParameterName = "@ResumeData";
    Para1.SqlDbType = SqlDbType.Image;
    Para1.Value = ResumeData;
    Cmd.Parameters.Add(Para1);
    Cmd.ExecuteNonQuery();
}


public Document FileToByteArray(string fileName)
       {
           byte[] fileContent = null;

           System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
           System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fs);
           long byteLength = new System.IO.FileInfo(fileName).Length;
           fileContent = binaryReader.ReadBytes((Int32)byteLength);
           fs.Close();
           fs.Dispose();
           binaryReader.Close();
           Document objDoc = new Document();
           objDoc.DocName = fileName;
           objDoc.DocContent = fileContent;
           return objDoc;
       }
      public class Document
      {
       public int DocId { get; set; }
       public string DocName { get; set; }
       public byte[] DocContent { get; set; }
      }


private void btnSubmit_Click(object sender, EventArgs e)
      {
              //many statements

              Document objDoc = new Document();
              objDoc.DocContent = Attachmnt;//attachment defined as byte[] Attachment;
              objEntity.ResumeData_ = objDoc.DocContent;
              objEntity.Submit();
              MessageBox.Show("Records Added Successfully!");


          this.Close();
      }
 
Share this answer
 

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