|
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 )
|
|
|
|
|
OK, you're right! Thanks you so much Christian Graus, I've fixed it
Best regards!
|
|
|
|
|
One more simple question (but difficult for me!!):
How to save the image file into the folder, which contains my project??
I have tried to use
<br />
string path = Application.ExecutablePath + "\\result.bmp";<br />
img.Save("C:\\result.bmp");<br />
But path is wrong ("\\" not "\" for location address of file). Thank you.
|
|
|
|
|
Path.Combine(Application.StartupPath, "result.bmp")
Of course, your code snippet will still save to C for obvious reasons, but the ExecutablePath contains the filename, too. Path.GetDirectory will strip a filename if you ever need to.
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 )
|
|
|
|
|
Thanks you so much, I understood already.
|
|
|
|
|
Um your welcome.
|
|
|
|
|
Hi,
I want to calculate this formula upon radian, not degree. (because I want to use it in an Area formula)
teta - sin(teta)
that : teta = 2*ArcCos(d)
I'd wrote this but it's wrong:
(2 * (Math.Acos(d) * 180 / Math.PI)) - Math.Sin((2 * (Math.Acos(d) * 180 / Math.PI)) * Math.PI / 180)
what's the correct?
Best wishes
|
|
|
|
|
Isn't 180/PI how you convert to degrees ? Either way, you just do whatever conversions you need to get it to where you want it.
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 )
|
|
|
|