Hi Guys, I am working on a project called Job portal website, where Registration form has taken place. And in that Registration form "Upload File" control Button is there. I wants to write some code for Upload files and its should accept all types of files like Doc, xls, pdf, etc then it shoud get store in sql database 2008.
So how to save files in sql server 2008?? Please Help\
here is the Sql Code...
Create proc [dbo].[proc_RegistrationMaster]
(
@UserName varchar(100),
@CreatePassword varchar(100),
@FirstName varchar(100),
@LastName varchar(100),
@Gender varchar(10),
@Addresss varchar(max),
@EmailID varchar(50),
@MobileNo bigint,
@LandLineNo bigint,
@UG_Graduation varchar(50),
@PG_Graduation varchar(50),
@Doctorate varchar (50),
@ResumeHeadLine varchar(100),
@TotalExperince varchar(50),
@CurrentCTC varchar(50),
@ExpectedCTC varchar(50),
@FunctionalArea varchar(100),
@IndustryDomain Varchar(100),
@UploadResume varbinary(max)
)
as
begin
insert into RegistrationMasters
values
(
@UserName,
@CreatePassword,
@FirstName,
@LastName,
@Gender,
@Addresss,
@EmailID,
@MobileNo,
@LandLineNo,
@UG_Graduation,
@PG_Graduation,
@Doctorate,
@ResumeHeadLine,
@TotalExperince,
@CurrentCTC,
@ExpectedCTC,
@FunctionalArea,
@IndustryDomain,
@UploadResume
)
end
here is the c# code...
public void btn_Register_Click(object sender, EventArgs e)
{
string Connstrr = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(Connstrr);
Conn.Open();
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
Stream str = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(str);
Byte[] size = br.ReadBytes((int)str.Length);
SqlCommand insertCommand = new SqlCommand("proc_RegistrationMaster",Conn);
insertCommand.CommandType = System.Data.CommandType.StoredProcedure;
insertCommand.Parameters.Add("@UserName",txtUserName.Text.ToUpper());
insertCommand.Parameters.Add("@CreatePassword",txtCreatePassword.Text.ToUpper());
insertCommand.Parameters.Add("@FirstName",txtFirstName.Text.ToUpper());
insertCommand.Parameters.Add("@LastName",txtLastName.Text.ToUpper());
insertCommand.Parameters.Add("@Gender",RBGender.SelectedItem.Text.ToUpper());
insertCommand.Parameters.Add("@Addresss", txtAddress.Text.ToUpper());
insertCommand.Parameters.Add("@EmailID",txtemailID.Text.ToUpper());
insertCommand.Parameters.Add("@MobileNo",txtMobileNo.Text);
insertCommand.Parameters.Add("@LandLineNo",txtLandlineNo.Text);
insertCommand.Parameters.Add("@UG_Graduation",ddUGGraduation.SelectedItem.Text.ToUpper());
insertCommand.Parameters.Add("@PG_Graduation",ddPGGraduation.SelectedItem.Text.ToUpper());
insertCommand.Parameters.Add("@Doctorate",ddDoctorate.Text.ToUpper());
insertCommand.Parameters.Add("@ResumeHeadLine",txtResumeHeadline.Text);
insertCommand.Parameters.Add("@TotalExperince",ddTotalExperienceFrom.SelectedItem.Text + "Year" + ddTotalExperienceTo.SelectedItem.Text + "Month");
insertCommand.Parameters.Add("@CurrentCTC",ddCurrentCTCLakh.SelectedItem.Text + "Lakh" + ddCurrentCTCThousand.SelectedItem.Text + "Thousand");
insertCommand.Parameters.Add("@ExpectedCTC",ddExpectedCTCLakh.SelectedItem.Text + "Lakh" + ddexpectedCTCThousand.SelectedItem.Text + "Thousand");
insertCommand.Parameters.Add("@FunctionalArea",ddFunctionalArea.SelectedItem.Text);
insertCommand.Parameters.Add("@IndustryDomain",ddIndustriesDomain.SelectedItem.Text);
insertCommand.Parameters.AddWithValue("@UploadResume", "Application/Word");
insertCommand.ExecuteNonQuery();
Now When i Run this Code I am Getting Error. And the Error is
"Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query."
Guys Please Help