Is this good way?
- private void Button2_Click(object sender, EventArgs e) //Save pdf in database
- {
- byte[] filedata = null;
- MemoryStream ms = new MemoryStream();
- filedata = ms.GetBuffer();
- axAcroPDF1.src = LocalEncoding.GetString(ms.ToArray());
- using (SqlConnection openCon = new SqlConnection(cs))
- {
- string saveStaff = "declare @maxNo integer = 0 select @maxNo = isnull(max(number), 0) from [dbo].[documents]; Set @maxNo=@maxNo+1; INSERT into dbo.documents (number,file_location, pdf_file) VALUES (@maxNo,@file_location,@pdf_file)";
- using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))
- {
- querySaveStaff.Connection = openCon;
- querySaveStaff.Parameters.Add("@file_location", SqlDbType.VarChar, 255).Value = file_locationTextBox.Text;
- querySaveStaff.Parameters.AddWithValue("@pdf_file", SqlDbType.VarBinary).Value = filedata;
- openCon.Open();
- querySaveStaff.ExecuteNonQuery();
- openCon.Close();
- }
- }
- }

Shweta LodhaRank #31 · 39.8K reputationPosted Aug 5, 2018, 9:57 PM EDT
Raghavendar SwaminathanRank #788 · 2.9K reputationPosted Aug 5, 2018, 9:59 PM EDT
Raghavendar SwaminathanRank #788 · 2.9K reputationPosted Aug 5, 2018, 10:07 PM EDT
Raghavendar SwaminathanRank #788 · 2.9K reputationPosted Aug 5, 2018, 10:21 PM EDT
Raghavendar SwaminathanRank #788 · 2.9K reputationPosted Aug 5, 2018, 10:32 PM EDT
Shweta LodhaRank #31 · 39.8K reputationPosted Aug 5, 2018, 11:13 PM EDT
Goran BibicRank #993 · 2K reputationPosted Aug 5, 2018, 10:02 PM EDT
Goran BibicRank #993 · 2K reputationPosted Aug 5, 2018, 10:08 PM EDT
Goran BibicRank #993 · 2K reputationPosted Aug 5, 2018, 10:10 PM EDT
Raghavendar Swaminathan
But need some helpGoran BibicRank #993 · 2K reputationPosted Aug 5, 2018, 10:28 PM EDT
Raghavendar Swaminathan