TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Michael Clinton
NA
349
0
Using AsyncFileUpload and stored procedure
Oct 25 2020 5:49 AM
I been over a lot of AsyncFileUpload that save to hard drive and save to DB, but with not a stored procedure.
I tried with the following code, but when I view the database, I get 0x89 and my varbinary(max) data field.
Thanks,
if
(AsyncFileUpload1.HasFile && AsyncFileUpload1.PostedFile !=
null
)
{
string
filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
string
contentType = AsyncFileUpload1.ContentType.ToString();
using
(Stream fs=AsyncFileUpload1.PostedFile.InputStream)
{
using
(BinaryReader br =
new
BinaryReader(fs))
{
byte
[] bytes = br.ReadBytes((Int32)fs.Length);
using
(SqlConnection conn1 =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"xxx"
].ConnectionString))
{
SqlCommand sqlcmd =
new
SqlCommand(
"usp_CustomerClientSave"
, conn1);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add(
new
SqlParameter(
"@ClientID"
, System.Data.SqlDbType.Int)).Value = Convert.ToInt32(Decrypt(Request.QueryString[
"id"
].ToString()));
sqlcmd.Parameters.Add(
new
SqlParameter(
"@UpdatedByID"
, System.Data.SqlDbType.Int)).Value = Convert.ToInt32(Session[
"id"
].ToString());
sqlcmd.Parameters.Add(
new
SqlParameter(
"@filename"
, System.Data.SqlDbType.VarChar,100)).Value = filename;
sqlcmd.Parameters.Add(
new
SqlParameter(
"@ContentType"
, System.Data.SqlDbType.VarChar, 25)).Value = contentType;
sqlcmd.Parameters.Add(
new
SqlParameter(
"@Data"
, System.Data.SqlDbType.VarBinary,8000)).Value = bytes;
try
{
conn1.Open();
sqlcmd.ExecuteNonQuery();
}
catch
(Exception ex)
{
throw
new
System.Exception(ex.ToString());
}
finally
{
conn1.Close();
sqlcmd.Dispose();
}
}
}
}
}
Reply
Answers (
1
)
SAAS model database
Select2 CURD demo in MVC.Net With Jquery?