|
|
Depending on what is the result value and the precision that you want. Float has 7 while Double has 14 (IIRC) precision so it's generally more precise. But still depending on the value.
|
|
|
|
|
Thanks darkelv,
Any tutorials on this topic?
regards,
George
|
|
|
|
|
I've had float's giving some rather... Awkward answers when dealing with unnaturally large / small numbers.
Use double
double a = 9249716388365591935;<br />
double b = 0.000000000000000000000000000000000001;<br />
double c = (a / b);<br />
MessageBox.Show(c.ToString());
Although, that's the limit of double - "a" cannot be any larger (An extra digit)...
Although, if you actually NEED any larger numbers.....
I'll try find something :p
- Reelix
|
|
|
|
|
Thanks Reelix,
Let me know if you find any good tutorials.
regards,
George
|
|
|
|
|
|
Thanks Reelix!
Good link!
regards,
George
|
|
|
|
|
Moral of the Story:
double j;
|
|
|
|
|
Decimal should be better than double in C#, I mean precise and range, right?
regards,
George
|
|
|
|
|
Might...
Never used decimal, to be honest...
Which brings up one of the question:
Why so many data types? :p
Why have int when you have double and decimal?
|
|
|
|
|
If you do not use double type, what types do you use?
regards,
George
|
|
|
|
|
Hello everyone there.
My name is Sachin.
Can anyone tell me how to count the number of rows using C#.NET?
I'm using MS ACCESS as my database source.
I'll be waiting for your replies.
Thanks in Advance.
Regards
Sachin Hundekar
|
|
|
|
|
Get row count from datagridview:
datagridview.rowcount
Get row count from dataset:
dataset.table[0].rows.count
hope this help you
|
|
|
|
|
This is bad advice. Why do you want to retrieve all the rows to get just the row count of a table?
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
erm..my suggestion is accrodding on after retrive data from database.Sure i am agree that using SELECT statement is the best when user would like to get the row count in database.
|
|
|
|
|
Am not familiar with Access, but surely SELECT COUNT(1) FROM tableName should do the trick? There should be plenty of samples on Google.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Hello Sachin,
If you are using a DataSet to connect it with Access table, you may use following syntax –
myDataSet.Tables[0].Rows.Count
If you do not know how to use DataAdapter, Connection object and DataSet I would recommend you to study Ado.Net first.
Just to give you some idea, basic code to connect to one data base file and getting its row count will look like this –
----------------------------------------------------
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\YourDatabaseFolder\\Nwind.mdb;Persist Security Info=False");
DataSet ds=new DataSet();
OleDbDataAdapter da;
private void Form1_Load(object sender, EventArgs e)
{
da= new OleDbDataAdapter("select * from customers",con);
da.Fill(ds);
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show( ds.Tables[0].Rows.Count.ToString());
}
------------------------------------
I hope this helps.
-Ajay.
-------------------------
www.componentone.com
-------------------------
|
|
|
|
|
Hello masters,
I have written a small project like this:
<br />
...<br />
try<br />
{<br />
img.Save("C:\\result.bmp");<br />
}<br />
finally<br />
{<br />
img.Dispose();<br />
}<br />
...<br />
Everything seemed good until I got a message box from Program.cs:
ArgumentException was unhandled. Parameter is not valid...
I can not find any mistake from my code, maybe something's wrong with my toolboxes' name?
Thanks for any help!
|
|
|
|
|
where is img defined ? Perhaps a using block would be nicer ?
What's the stack trace, that will give you a better idea where it goes wrong ? Have you used reflektor to look at the .NET library source and see what causes this exception to be thrown ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thank you so much for quick reply Christian Graus,
this is my code:
<br />
...<br />
private void btnCreateImage_Click(object sender, EventArgs e)<br />
{<br />
Bitmap img = new Bitmap(MaxSize, MaxSize);<br />
for (int i = 0; i < MaxSize; i++)<br />
{<br />
for (int j = 0; j < MaxSize; j++)<br />
{<br />
if (obj.Img_In_Process[i, j] < 0) img.SetPixel(j, i, Color.FromArgb(0, 0, 0));<br />
else img.SetPixel(j, i, Color.FromArgb(255, 255, 255));<br />
<br />
}<br />
}<br />
picbox.Image = img;<br />
<br />
try<br />
{<br />
img.Save("C:\\result.bmp");<br />
}<br />
finally<br />
{<br />
img.Dispose();<br />
}<br />
<br />
}<br />
...<br />
I'm newbie at C#. In my project, I'm just trying to save an .bmp image from a matrix.
|
|
|
|
|
using (Bitmap img = new Bitmap(MaxSize, MaxSize))
{
for (int i = 0; i < MaxSize; i++)
{
for (int j = 0; j < MaxSize; j++)
{
if (obj.Img_In_Process[i, j] < 0) img.SetPixel(j, i, Color.FromArgb(0, 0, 0));
else img.SetPixel(j, i, Color.FromArgb(255, 255, 255));
}
}
picbox.Image = img;
//string path = Application.ExecutablePath + "\\result.bmp";
//MessageBox.Show(path);
img.Save("C:\\result.bmp");
//img.Save(path);
}
will always dispose of your image when the scope ends.
I would suggest you read my image processing articles for info on how to efficiently do this sort of operation.
And, I would need to see the stack trace to get an idea of why you are getting an exception. Does result.bmp exist ? Can you fix the exception by deleting it ? My first guess would be that you have that image open somewhere else, and so cannot save over it, but I'd expect the message to be different.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
you should not dispose of the image when it is still in use; it is in use
thru your picbox.Image = img; line.
If you want to get rid of the image, first do picbox.Image = null;
or something like that.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Which line does the exception get thrown?
|
|
|
|
|
Thanks for your help Jordanwb, I got message at this line:
<br />
...<br />
static class Program<br />
{<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
Application.Run(new frmMain()); <<<<< This line<br />
}<br />
}<br />
|
|
|
|
|
OK, that means that the exception is throw outside your try block, and is not caught anywhere inbetween. What's the stack trace ? What happens if you step through your code to see what line blows up ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|