hello sir how to fix this problem please check my code and please suggest me how to use convert function thanks for advance sir...
Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query..Net SqlClient Data Provider
protected void btnsave_Click(object sender, EventArgs e)
{
String str = "";
for (int i = 0; i <= chkBoxEx.Items.Count - 1; i++)
{
if (chkBoxEx.Items[i].Selected)
{
if (str == "")
{
str = chkBoxEx.Items[i].Text;
}
else
{
str += "," + chkBoxEx.Items[i].Text;
}
}
}
string insertSql;
string qualification = qualificationdetails.Text;
string agedetail = Agedetails.Text;
string importentdate = ImportentDate.Text;
string Applicationfeedetail = Applicationfeedetails.Text;
string postdetails = Numberofpostdetails.Text;
//lbllastdate.Text =ucdate.sel=
lbllastdate.Text = ucdate.SelectedDate;
string filePath = FileUpload1.PostedFile.FileName; // getting the file path of uploaded file
string filename1 = Path.GetFileName(filePath); // getting the file name of uploaded file
string ext = Path.GetExtension(filename1); // getting the file extension of uploaded file
string type = String.Empty;
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs); //reads the binary files
Byte[] bytes = br.ReadBytes((Int32)fs.Length); //counting the file length into bytes
string pdf = Convert.ToString(bytes);
insertSql = "INSERT INTO [latestsarkarijobdb].[dbo].[TBL_jobdetails]([job_name],[board_name],[JobHeaderMenuName],[job_category],[jobsub_category],[state],[qualification_details],[qualification],[post_date],[last_date],[age_details],[importent_date],[application_fee_details],[post_detailsnumberof],[apply_online_link],[notification_name],[notification_type],[notification_data],[official_website_link],[apply_offline_link],[chalan_link],[how_to_link])VALUES('" + txtposts.Text + "','" + bordName.Text + "','" + ddlJobMenuList.SelectedItem + "','" + ddljobcategory.SelectedItem + "','" + ddljobsubcategory.SelectedItem + "','" + ddlstate.SelectedItem + "','" + qualification + "','" + str + "','" + Convert.ToDateTime(txtpostdate.Text) + "','" + Convert.ToDateTime(lbllastdate.Text) + "','" + agedetail + "','" + importentdate + "','" + Applicationfeedetail + "','" + postdetails + "','" + txtApplyOnlineLink.Text + "','" + filename1 + "','" + type + "','" + pdf + "','" + txtOfficialWebsite.Text + "','" + txtApplyoffline.Text + "','" + txtchalan.Text + "','" + txthowtoapply.Text + "')";
SqlConnection myconnection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(insertSql, myconnection);
//cmd.Parameters.Add("@notification_data", SqlDbType.Binary).Value = bytes;
Response.Write(insertSql);
int add = 0;
try
{
myconnection.Open();
add = cmd.ExecuteNonQuery();
lblinfo.Text = add.ToString() + " records inserted.";
bordName.Text="";
txtposts.Text="";
txtApplyOnlineLink.Text="";
//txtdownloadsyllabus.Text="";
//txtDownloadNotification.Text="";
txtOfficialWebsite.Text="";
txtposts.Text = "";
}
catch (Exception err)
{
lblinfo.Text = err.Message + err.Source;
}
finally
{
myconnection.Close();
}
}