What this exception means? C# winforms - c#

I'm trying to display images from a database table to my dataGridView control.
Other cells display image. But some doesn't and throws this exception:
What does this exception means? What should I do to fix it?

In all likelihood, it means that your image data is invalid. Try extracting the image data by another means, like a simple console app, and pass that to Image.FromStream. Or serialize it out and try to open it in an external image editor. You might get a more informative error message that way.

According to MSDN your call will result in this exception if the Stream has an invalid format

If some invalid in bytes entered then it wont display properly.
If you tried with a Insert query , then this problem may come. Try to insert image from code only.Hope it will work fine.

It appears to indicate that there was an error creating the image from a Stream (probably handled within ADO.NET rather than in your code). If it's working for some images and not others then start by double-checking the data in the database, and look for differences between them.

There might be the error from database.Please once check your Code again

If, as you say, the images display in some rows but not others it's the data, not your code - The images have been captured incorrectly.

Related

Get the data copied after Ctrl+ C operation to a variable

I have some data in notepad and have performed Sendkeys("Ctrl+C") using keyboard library.I want to get the copied data to a variable in C# code.
How to get the data to variable programmatically.
I tried clipboard.GetText() API and it is giving empty string.
Your could get any data using Clipboard.GetDataObject().
See the example at msdn

Retrieve and Place Image From SQL Db to a PictureBox In C# WinFormApp

I want to save and retrieve an image from database and place it in a picturebox in my windows form application.
Does any one have any code for it? and please tell me the data type in SQL that I have to use for storing my image (which one is better, Varbinary(MAX) or Image?)
this is the code i'm using for taking the image from a PicturBox and making it into a binary and storing it into a Varbinary(MAX) in the Database and when I Run The code It says: Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.
System.IO.MemoryStream mymemory = new System.IO.MemoryStream();
img.Save(mymemory,Pbox.Image.RawFormat);
Byte[] myarray = mymemory.GetBuffer();
What should I do?
If anyone has better code please help me with copying the code here for me
any help will be appreciated.
Based on your prior "connection strings" question, the best answer would be to not save the image in that table, only a reference to it; either by using a filestream table or by a text field containing the file system location.

Parameters not being passed correctly through code

My report gets data from a stored procedure. Two of the six parameters are dates (toDate and fromDate.) I integrate the report with C# Winforms and I pass the parameters through code the code with:
reportDocument.setParamterValue(0,paramValue);
The report works fine but does not render data despite showing the column header properly. When I refresh the report, it pops up the parameter window again. When I enter the parameters through that window the data shows, including column headers. But it doesn't work when I pass parameters through code.
How can I resolve this?
It looks like this:
CRPT.SetParameterValue("smonth", Servercls.month);
See this link for more info.
I suggest first of all call procedure in c# environment and save result in datatable and then send datatable to crystal report.
I found the error.
First it was not working with setting parameters through indexing. so i set the parameters through name as reds suggested.
second i was missing the parameters binding with report viewer object.
so i added the following line and it worked
crystalReportViewer.ParameterField.addRange(reportDocument.ParameterFields);
Thanks for the answers guys.

Access INSERT query with 150+ parameters and a data mismatch. How to find which param is wrong?

I'm reading a tab delimited text file into a String[]. Then, go thru the array line by line, split it into individual elements (currentLine.Split('\t')), make changes to the elements as needed, and then do a Parameters.Add to add each element as a parameter to the query string.
For the most part, it works and has added stuff to the Access table. However, it hit something in the data that it didn't like, and I'm having trouble determining which element is causing the data mismatch. The only error I'm getting (VS Express 2012) is Data type mismatch in criteria expression.
Is there a way to see which parameter is causing the error? I can tell which line it is by looking at what's already been added to the table, but I don't see where the problem is.
Thanks!
Your question seems pretty general although here are some techniques that will help you resolve it:
Wrap your database insert/update statement in a try / catch. Within the catch block write the parameters that were active at time of the insert.
Inspect the exception for an inner exception that will likely have more specific details of the invalid parameter/value.

conditions handling in reportviewer control

I have report in .rdlc format. I have inserted table in my report which is filled in programatically(in runtime) from datatable(which is also filled by dataadapter programatically). Also I want in table to use conditional formatting - background color of cell based on value. To do that in BackGroundColor property of needed column expression was inserted:
=iif(cdbl(Fields!MyField.Value),"Green","Yellow")
I haven't mentioned that all fields in my datatable are string. Therefore i use cdbl function to convert string to double. And when I render report, i don't have the desired result.
Therefore questions:
How to make sure there is no parsing error?
Is it possible to see step by step computation (as in excel)?
And what else error could be?
I suspect problem might be in culture.
The quickest way to test is to call
=iif(cdbl("3.14"),"Green","Yellow")
=iif(cdbl("3,14"),"Green","Yellow")
And see if it's working.
I don't have a reporting services right now and can't test it. I think you can do a tryParse in Reporting services.

Categories

Resources