.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

Converting to stream after resize for SQL Insert

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :ASP.Net
 
Hey guys,I'm running with this. Public Function ImageData(ByVal fu As FileUpload) As Byte() If fu.HasFile Then Dim imageBytes As Byte() = New Byte(fu.PostedFile.InputStream.Length) {} fu.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length) Return imageBytes Else Return Nothing End If End Function Public Function ImageResize(ByVal fu As FileUpload) As Bitmap Dim thumbWidth As Integer = 1024 Dim image As System.Drawing.Image = image.FromStream(fu.PostedFile.InputStream) 'Create a System.Drawing.Bitmap with the desired width and height of the thumbnail. Dim srcWidth As Integer = image.Width Dim srcHeight As Integer = image.Height Dim thumbHeight As Integer = (srcHeight / srcWidth) * thumbWidth Dim bmp As New Bitmap(thumbWidth, thumbHeight) 'Create a System.Drawing.Graphics object from the Bitmap which we will use to draw the high quality scaled image Dim gr As Graphics = Graphics.FromImage(bmp) 'Set the System.Drawing.Graphics object property SmoothingMode to HighQuality gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality 'Set the System.Drawing.Graphics object property CompositingQuality to HighQuality gr.CompositingQuality = Drawing2D.CompositingQuality.HighQu


View Complete Post


More Related Resource Links

Insert value using Table Value Functions

  
a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

Insert Rows with a GridView

  
In ASP.NET version 1.x, I used the footer on the DataGrid control to insert new rows by placing a series of TextBox, DropDownLists, CheckBoxes etc. controls on it and then handling a save button. This also works with the GridView in version 2.0 but with one major exception: if your data source is empty, the GridView will hide your footer (and header) and only display the EmptyDataText.

SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

  
Sometimes you end up with a return value of -1 when using the SqlClient.SqlCommand.ExecuteNonQuery method.

Why is that?



Well, the ExecuteNonQuery method is there for statements for changing data, ie. DELETE / UPDATE /INSERT, and the returned value are the number of rows affected by that statement.

When checking the documentation we can see that there are some conditions that return -1.



For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of

rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

WebMatrix conversion failed when converting from a character string to uniqueidentifier?

  

I am trying to retrieve xml from a small function in my .cshtml page. Its throwing me an error. This however, runs fine in a console/form environment.

It takes 3 parameters and 1 exception.

myDll.GetXML(year, username, uniqueidentifier, out ex);

When I run this page I get the error, "Conversion failed when converting from a character string to uniqueidentifier."

Or a stack of.

System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting from a character string to uniqueidentifier.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

   at System.Data.SqlClient.SqlDataReader.get_MetaData()

   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBeha

Insert Error not helpful

  

Hi,

I am using VS2010

When I try to updated or insert a record in my User table I am getting an error that does not make sense to me and I cannot figure out what is wrong.

Also, when I try to insert a new record I get a validation error saying that the Id is required. However it is an identity field in the db so it should not be necessary to send it to the server.

Could you please shed some light?

 

An error has occurred.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.Web.UI.WebControls.EntityOperationException: An error has occurred.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace:


[EntityOperationException: An error has occurred.]
   Microsoft.Web.UI.WebControls.DomainDataSourceView.PerformCudOperation(ChangeSetEntry operation, Action`1 operationPerformingEvent, Action`1 operationPerformedEvent) +331
   Microsoft.Web.UI.WebControls.DomainDataSourceView.UpdateObject(Object oldEntity, O

Detecting Edit or Insert Page

  

I am coding a .cs file that handles the metadata for a particular table. I am putting a custom validation that allows me to update or insert only if the PubMedID is not already in the database. This would be easy except that the PMID should also be allowed to be null as some of the references in the database were not from PubMed. So i perform a query on the database to see if there is already an identical PMID in the database. This works great when using Insert. However, when using Edit, it does not. The PMID is already in the database because the one currently being edited has the same PMID!!! So I know exactly how to change my query etc. However, I do not know how to tell from inside this Edit/Insert agnostic page, which one it is being called from. Thanks for your help! 


how To Insert the single quotes in sqlcommand in asp.net

  

Hi all

    i am developed on simple user registeration application in that i gave  address field .when i am trying to enter something like this (1st main,b'lore) but wont take while inserting.

my query is

sqlcommand cmd=new sqlcommand("insert into registeration_form(name,address)values('"+txtname.text+"','"+txt_address+"')",con);


how can i pass the  quotes also to my query please if any one know reply me.


Thanks

G Dinakaran



Insert data to Excel using OLEDB

  

Hi,

I am trying to insert data to Excel Document using OLEDB as follows:-

 sql = "Insert into [MyFirstSheet$] (" + Title1 + "," +Title2 + "," + Title3 + ") 
values('" + Value1 + "','" + Value2 + "','" + Value2 + "')";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();

 sql = "Insert into [MyFirstSheet$] (" + Title1 + "," +Title2 + "," + Title3 + ") 

values('" + Value1 + "','" + Value2 + "','" + Value2 + "')";

myCommand.CommandText = sql;

myCommand.ExecuteNonQuery();

But, the Title1 ,Title2, Title3 are in the 3rd row of the Excel Document. So, the data is not inserted.

How to insert Image (jpeg) into MS Word Programmatically using VB.NET

  

Hi there,

Can someone help me on How to insert Image (jpeg) into MS Word Programmatically using VB.NET..not C#.NET??? Sad

I could hardly find any articles for the coding. Preferably using Bookmark...can i have the sample code.

Thanks,

 


resize png at time of uploding without loosing tranparancy of img

  

 

i have tryed so many code to resize n compress png img but after resize it loose it's tranparancy ,

any one have good code to fix this problem.



Bad quality after resize jpeg

  

Hi,

I wrote code that resize my photo to thumbnail (100x100px). The thumbnail is ok (is blur) on serwer (Windows Serwer 2008 x64) and the thumbnail is very bad (no blur and pixels are big) on serwer (Windows Serwer 2008 x86). Both serwers have framework .net 4.0.

I wrote code on VS 2010.

Below is my code:

public static void MakeThumbnail(string path, string prefix, string filename, Stream stream, string mime, int fixedWidth, int fixedHeight, bool allowCrop)
{
string newFullname = path + "\\" + prefix + filename;

//oryginalny obrazek
Image sourceOriginalImage = Image.FromStream(stream);

int width = sourceOriginalImage.Width;
int height = sourceOriginalImage.Height;

double widthD = Convert.ToDouble(width);
double heightD = Convert.ToDouble(height);
double fixedWidthD = Convert.ToDouble(fixedWidth);
double fixedHeightD = Convert.ToDouble(fixedHeight);

int newWidth = 0;
int newHeight = 0;

int cropX = 0;
int cropY = 0;

newWidth = fixedWidth;
newHeight = (int)(fixedWidthD / Xp);
cropY = Convert.ToInt32((newHeight -

Problem with Resize on x64/x86

  

Hi,

I wrote code that resize my photo to thumbnail (100x100px). The thumbnail is ok (is blur) on serwer (Windows Serwer 2008 x64) and the thumbnail is very bad (no blur and pixels are big) on serwer (Windows Serwer 2008 x86). Both serwers have framework .net 4.0.

I wrote code on VS 2010.

Below is my code:


public static void MakeThumbnail(string path, string prefix, string filename, Stream stream, string mime, int fixedWidth, int fixedHeight, bool allowCrop)
{
string newFullname = path + "\\" + prefix + filename;

//oryginalny obrazek
Image sourceOriginalImage = Image.FromStream(stream);

int width = sourceOriginalImage.Width;
int height = sourceOriginalImage.Height;

double widthD = Convert.ToDouble(width);
double heightD = Convert.ToDouble(height);
double fixedWidthD = Convert.ToDouble(fixedWidth);
double fixedHeightD = Convert.ToDouble(fixedHeight);

int newWidth = 0;
int newHeight = 0;

int cropX = 0;
int cropY = 0;

newWidth = fixedWidth;
newHeight = (int)(fixedWidthD / Xp);
cropY = Convert.T

Easy image processing(grayscale, sepia, negative, resize, brightness, contrast and opacity)

  
Howdie y'all,

I see a lot of questions in this forum about resizing images. Recently I created a code sample(with downloadable webapp), right here.

The class (downloaded or created) allows for very fast and easy processing of your images. And a lot of problems over here can be solved by simply using that class. I thought it might help to mention the code sample in this forum as well.

Cheers,

Wes

Converting ReportDocument object into byte array ?

  

Hi All,

          Is it possible to convert the Report Document object as a byte array and store it in SQL , later retrieve and assing it to a report ?

 


Problems converting VS 2003 project to VS 2008

  

Hi!

I'm having problems converting a VS 2003 project to VS 2008 (tried 2005 as well, same problem). There are several problems;
a) I don't have VS 2003 installed.
b) The project is a web service, however I'm not sure what type of VS project it was created as.
c) The general knowledge about the project setup is..slim.

I get a error message using the conversion wizard, however, I'm not familiar with the tool and I cannot quite find any good information on Google for it, so I am left with a error message I do not understand.

Conversion Issues - myProject.csproj:
Unable to open the Web site 'C:\local\path\to\project\myProject.csproj'. The Web site 'C:\local\path\to\project\myProject.csproj' does not exist.

The web service is not intended to run on the dev machine, it is copied to a test or a prod server. However, I do not know how this was done previously. I'm thinking that in order to convert, it has to access the server on which it should run (which is set somehow in a config maybe). But that doesn't actually make any sence..

If anyone could shed light on this, I would really appreciate it.

Thank you.


Converting Time formats

  

Hi guys,

So ive been converting an asp website to asp.net. What i did was run the migration wizard in the old VS2003, then when importing it bk into vs2008, i belive it upgraded it agin. I have been plodding along correcting basic erros and have come stuck with this one. Originallany the site has two input types, one for date and one for time. the new script is below with error im getting. I manged to get the date correct but the time is more tricky. Any suggestions would be appreciated.

 

 

Date = FormatdateTime(IIF(IsDBNull(MyRs1.Fields.Item("").Value), Nothing, MyRs1.Fields.Item("").Value), DateFormat.ShortDate)

Time = FormatdateTime(IIF(IsDBNull(MyRs1.Fields.Item("").Value), Nothing, MyRs1.Fields.Item("").Value), DateFormat.ShortTime)

 

Exception Details: System.InvalidCastException: Conversion from type 'Double' to type 'Date' is not valid.

Source Error:

Line 74: 
Line 75: 'TODO Need to correct the format 
Line 76:   Time= FormatDateTime(IIf(IsDBNull(MyRs1.Fields.Item("").Value), Nothing, MyR

Help converting vbscript to vb.net

  

Can anyone help me convert the below vbscript to vb.net:

 

On Error Resume Next

Dim sRunTime,sSitupCount,sPushupCount,sRunMin,sRunSec,sRunScore,sCompScore,sBodyComp
Dim iCompositeScore

Set oRE = New RegExp

sRunTime = InputBox("Enter your run time")
oRE.Pattern = "[0-5][0-9]:[0-5][0-9]"

If oRE.Test(sRunTime) = True Then
 WScript.Echo "Pattern Match"
Else
 MsgBox "You must enter a valid run time in the following format: ""mm:ss""." & vbCr & "Please run the application again."
 WScript.Quit(Err.Number)
End If

sRunMin = Left(sRunTime,InStr(sRunTime,":")-1)
sRunSec = Right(sRunTime,InStr(sRunTime,":")-1)

sBodyComp = InputBox("Enter your waiste measurement")
oRE.Pattern = "[2-6][0-9].[0,5]"

If Len(sBodyComp) = 2 Then
 sBodyComp = sBodyComp + ".0"
End If

If oRE.Test(sBodyComp) = True Then
 WScript.Echo "Pattern Match"
Else
 MsgBox "You must enter a waiste measurement in the following format: ""nn.n""." & vbCr & "Please run the application again."
 WScript.Quit(Err.Number)
End If

sSitupCount = InputBox

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend