Hi, I wrote the following code to retrieve an image from sql server. I am getting the output if i was not putting the where condition. But i want to pass the where condition as i require a specific image.
<HTML> <HEAD> <title>Retrieving Image from the Sql Server</title> <script runat=server> Public Sub Addperson(ByVal sender As Object, ByVal e As EventArgs) ' Create Instance of Connection and Command Object Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("Constring")) Dim myCommand As New SqlCommand("Select * from image where invoice_no =' Form1.txt_no.text '", myConnection) Try myConnection.Open() Dim myDataReader As SqlDataReader myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) Do While (myDataReader.Read()) Response.ContentType = myDataReader.Item("Image_Type") Response.BinaryWrite(myDataReader.Item("Image")) Loop myConnection.Close() Response.Write("Image successfully retrieved!") Catch SQLexc As SqlException Response.Write("Read Failed : " & SQLexc.ToString()) End Try End Sub
</script> </HEAD>
But i am getting the following error
Read Failed : System.Data.SqlClient.SqlException: Error converting data type varchar to bigint. 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(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.HasMoreRows() at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout) at System.Data.SqlClient.SqlDataReader.Read() at ASP.retrieve_aspx.Addperson(Object sender, EventArgs e) in D:\FILE SAVING IN DATBASE\Retrieve.aspx:line 19
Plz help me
|
| Author: Praveen Kumar 31 Mar 2008 | Member Level: Gold | Rating: Points: 2 |
I think your invoice_no is asking for integer value and you are giving varchar in textbox. please fix it first
|