Word or PDF into Database sql-server c#
private int SaveToDB(string imgName, byte[] imgbin, string imgcontenttype)
{
{
SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["DSN111"]);
SqlCommand command = new SqlCommand( "INSERT INTO Image (img_name,img_data,img_contenttype) VALUES ( @img_name, @img_data,@img_contenttype )", connection );
SqlCommand command = new SqlCommand( "INSERT INTO Image (img_name,img_data,img_contenttype) VALUES ( @img_name, @img_data,@img_contenttype )", connection );
SqlParameter param0 = new SqlParameter( "@img_name", SqlDbType.VarChar,50 );
param0.Value = imgName;
command.Parameters.Add( param0 );
param0.Value = imgName;
command.Parameters.Add( param0 );
SqlParameter param1 = new SqlParameter( "@img_data", SqlDbType.Image );
param1.Value = imgbin;
command.Parameters.Add( param1 );
param1.Value = imgbin;
command.Parameters.Add( param1 );
SqlParameter param2 = new SqlParameter( "@img_contenttype", SqlDbType.VarChar,50 );
param2.Value = imgcontenttype;
command.Parameters.Add( param2 );
param2.Value = imgcontenttype;
command.Parameters.Add( param2 );
connection.Open();
int noRowsAffected = command.ExecuteNonQuery();
connection.Close();
int noRowsAffected = command.ExecuteNonQuery();
connection.Close();
return noRowsAffected;
}
No comments:
Post a Comment