|
public string Dirty(int number)
{
if (number <= 0) return "";
switch (number/10 == 1 ? number : number%10)
{
case 1: return number + "st";
case 2: return number + "nd";
case 3: return number + "rd";
default: return number + "th";
}
} :->
xacc.ide-0.1.1 released! :) Download and screenshots
-- modified at 4:16 Tuesday 27th December, 2005
|
|
|
|
|
11st? 12nd?!!
Regards,
Rob Philpott.
|
|
|
|
|
|
And don't forget 13rd
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
|
|
|
|
|
I think that for any number whenever the digit at tenth place is '1' then 'th' is always appended to the number. For all other numbers ending with 1,2,3 digits are appended with 'st','nd','rd' respectively for all other digits 'th' is appended.
And this is my code.
public string Dirty(int number)
{
int num=number%100;
int tenplace=num/10;
if(tenplace==1)
{
return number + "th";
}
switch (number%10)
{
case 1:
return number + "st";
case 2:
return number + "nd";
case 3: return number + "rd";
default: return number + "th";
}
}
|
|
|
|
|
Very nice, but unless you want it to return
-21th, or 0th, you need to add:
try
{
if (number < 1) return "";
//YOUR CODE HERE
}
catch { return ""; }
If you don't add the try/catch and the number is too big you will get an error.
|
|
|
|
|
yeh u r right. But I think 0th is valid.
instead of
number < 1
we should use
number < 0
would work better
|
|
|
|
|
i can connect to serial comm port with C# 2003 .
It's very simple.
you only need to use MScomm32.ocx .
if anyone take care , you can email to me.
|
|
|
|
|
Hi,
I am trying to get the SqlDependency to work in an application. Here is the problem:
One windows application connects to northwind database using a user login. It then diplays the data in the Employees table.
Another project is using the the login as the previous App to display the same data BUT it displays an error when it gets to da.Fill(ds, "Customer");
The error is:
Message "When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance." string
Thanks
Here is code that I am using.
ds.Clear();
SqlConnection conn = new SqlConnection(txtConnect.Text);
conn.Open();
SqlCommand cmd = new SqlCommand(txtSelect.Text, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
//SqlDependency.Start(txtConnect.Text); //test...
SqlDependency dep = new SqlDependency(cmd);
//The ERROR is on this line...///////
da.Fill(ds, "Employees");
/////////////////////////////////////
grdDemo.DataSource = ds;
grdDemo.DataMember = "Employees";
|
|
|
|
|
im sorry to see that you're having this problem. i have a library class that does sql connections and returnes data sets, etc. you dont have to use the class but it might help to look at/implement the code and see if you get the same error. Hope this link leads you to a solution to your problem
http://www.codeproject.com/dotnet/COperationsSQL.asp
all sqlconnections, commands, data adapters, are encapsulated in this class making things a little bit easier when it comes to interfacing with a sql back end. best of luck
|
|
|
|
|
Hi,
My query is to do with the SqlDependency only.
Thanks
|
|
|
|
|
Hi there.
I am wondering regarding the Label control. I assigned some random numbers to some Label controls that then appear on screen, for example:
tnr8.Text = r.Next(117, 138).ToString();
tnr8.Location = new Point (20,20);
where tnr8 is the Label and r is an instance of the Random class.
I tried this but it didn´t work :
label3.Text = label1.Text + label2.Text;
How can I capture the value that is placed in the Labels? How can I add, subtract, multiply or divide the current value of the Labels that are on the screen as a result of the code?
Thanks in advance and merry christmas.
FJ
|
|
|
|
|
The Text property of the Label control is a string property. Therefore, when you do label1.Text + label2.Text , the runtime concatenates the strings.
To do what you want, you need to convert the string s to some numerical type. Therefore, you need something like
double result = double.NaN;
try
{
result = double.Parse( label1.Text ) + double.Parse( label2.Text );
}
catch( Exception ){}
label3.Text = result.ToString();
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi.
Thanks for the answer. I don´t get what the NaN is in :
double result = double.NaN;
Thanks again for your help!
FJ
|
|
|
|
|
double.NaN is "Not A Number" defined in IEEE floating-point specifications. This way, if you have non-numerical values in your Label s, then the "result label" will show "NaN" meaning that no arithmetic operation could get performed on the values.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi.
I tired what you suggested and it works. Thanks a lot
FJ
|
|
|
|
|
I feel glad that I could help. Happy coding!
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hello!
I am trying to implement a context menu for several different controls (more than one control have the same context menu) in C#.NET 2.0.
In .NET 1.1 we could just compare the 'sender' parameter in order to see which control has actually displayed the context menu and issued the command.
But in .NET 2.0 I get a reference to the tool strip item of the context menu in 'sender'...
How to see which control has actually used the context menu?
I already tried several different ways (like checking the controls with .Focused, etc.), but nothing worked
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
See if the eventargs parameter has an index property - I ran into the same kind of issue with a tab control (trying to determine which tab page generated the event) and found e.Index held the answer.
dpb
Darryl Borden
Principal IT Analyst
dborden@eprod.com
|
|
|
|
|
Dear All,
I know this section is regarding C# only,but I am entering regarding SQL Database. I am really sorry for this.
I want to Delete the SQL Database programmatically (using C#). I am using following code for Deleting Database.
----------------------------------------------------------
private void DeleteDatabase()
{
try
{
String conn = "server="+ strLocalIP +";database="+ "master" +";password="+ "sa" +";User id="+ "sa" +";";
SqlConnection sqc = new SqlConnection(conn);
sqc.Open();
SqlCommand sc = new SqlCommand();
sc.Connection = sqc;
sc.CommandText = "DROP DATABASE "+strDatabaseName;
sc.ExecuteNonQuery();
sqc.close();
}
-------------------------------------------------------------------
strLocalIP id computers IP
Through Query Analyzer 'DROP Database' is working fine but programmatically it's giving exception, 'connection is in use'
With Regards
Manoj
|
|
|
|
|
What exactly is the conn string and the sc.CommandText ?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
|
|
|
|
|
Dear Colin Angus,
The conn String is is the connection String containg computer information in which Database exists , Database name, user and password through which i can login to database.
String conn = "server="+ strLocalIP +";database="+ "master" +";password="+ "sa" +";User id="+ "sa" +";";
strLocalIP is actually is the IP of computer inwhich Database exists.
And sc is sqlcommand through which I execute the sql query.
Some one has suggested me to flush the connection pool. Please let me know How i can flush connection pool through C#.
Thanks & Regards
Manoj Kumar
|
|
|
|
|
No, I wanted the exact values of conn and sc.CommandText . I did not want a description of them. I know what they mean, I want to know what you wrote.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
|
|
|
|
|
Connection is in use or database is in use???Normally, when you want to delete a database, you need to disconnect all current connections.
|
|
|
|
|
Dear Johny Ng,
Even after disconnecting all the connections related with Database it's still giving same exception. Some one has suggested me to flush the connection pool, Please let me know How i can flush connection pool in C#.
Thanks & Regards
Manoj
|
|
|
|