|
Hi, In my database table i have column with data like
00987
78960
89760
08123
009876
when i read the value(00987) into the integer variable, then it contiana value as 987.
I need the value in integer variable as same(00987). How can i do this?
int k = Convert.ToInt16(dt.rows[i]["colname]);
G. Satish
|
|
|
|
|
00987 is the same as 987. If you read it into an integer variable, then it will remove leading zeros. If you want to display it as it is in the database, then convert it to a string instead of an integer
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Do you know how to count ?
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
This data is stored as a string in your database. 00987 is exactly the same as 987 - I assume you want it displaying as 00987; in which case you need to use a string to display it.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Satish - Developer wrote: when i read the value(00987) into the integer variable, then it contiana value as 987.
I need the value in integer variable as same(00987)
You have to do nothing (or just review your basic math course material), since 000987 = 987 holds for a integer.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I suppose that what you really wanted to ask is: how to read a data with leading zeros and don't loose these zeros.
You have two possibilities:
- Store the number asa string in your application and parse it each time you need it for calculations.
- Create a structure which would store a number of zeros (I would do it this way).
internal struct IntWithZeros
{
private int zerosCount, value;
public static implicit operator int(IntWithZeros x)
{
return x.value;
}
public static IntWithZeros Parse(string data)
{
IntWithZeros ret;
ret.zerosCount = 0;
while (data.Length > ret.zerosCount && data[ret.zerosCount] == '0') {
ret.zerosCount++;
}
ret.value = int.Parse(data);
return ret;
}
public override string ToString()
{
string s = value.ToString();
return s.PadLeft(s.Length + zerosCount, '0');
}
}
Greetings - Jacek Gajek
|
|
|
|
|
private void btnUseLeadingZero_Click(object sender, EventArgs e)
{
int MyNumber = 987;
string MyNumberWithLeadingZero = MyNumber.ToString("00000");
MessageBox.Show(MyNumberWithLeadingZero);
}
|
|
|
|
|
Simplier and better. 5 from me.
Greetings - Jacek Gajek
|
|
|
|
|
Hi guys,
I had just posted a question about getting the path of the current executable. Thanks to all those who responded. However, I found this peice of code while googling just now, and this really seems to work:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
System.Reflection.Assembly a = System.Reflection.Assembly.GetEntryAssembly();
string baseDir = System.IO.Path.GetDirectoryName(a.Location);
Console.WriteLine(baseDir);
Console.ReadLine();
}
}
}
Here, Console.WriteLine(baseDir); prints the path of the .exe.
However, I want that the current executable be copied and moved using the System.IO; .NET class library namespace.
Some thing like this:
Instead of printing the path address with Console.WriteLine(baseDir); , I want to replace it with: System.IO.File.Copy("basedir", "C:\\desiredlocation");
But this code:
System.IO.File.Copy("basedir", "C:\\desiredlocation"); doesn't seem to work.
Can anyone help me out?
|
|
|
|
|
ShreeR.Bhattacharjee wrote: System.IO.File.Copy("basedir", "C:\\desiredlocation");
'basedir' shouldn't be in quotes. And that code snippet will copy the entire directory. Useful if you have references you want preserving, but if you just want to copy the executable, you should be specifying a.Location as the first parameter of File.Copy, not basedir
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Hi Computa,
The case remains same though I apply a.Location as the first parameter of File.Copy method.
Throws exception.
Exception type:
IOException
Exception details:
The target file "C:\\DesiredLocation" is a directory not a file.
Anyway, let me explain the problem more clearly. All I want to do is to copy only the .exe file to C:\\DesiredLocation.
Lemme know, if I need to be more comprehensive.
|
|
|
|
|
Try (new System.Uri(a.CodeBase)).AbsolutePath according to MSDN. This is because the CodeBase property is the fully escaped URL, including the file:// part. File.Copy won't accept this, so you need to create a new Uri, which parses it properly, and use the AbsolutePath property (which gets the proper name)
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
I assume that you want to move the file you have referenced in the baseDir variable to the new location - this means you shouldn't put quotes around baseDir in File.Copy, because that's a string literal, not a variable. Change it to
File.Copy(baseDir, @"c:\desiredlocation");
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi Pete,
The code:
File.Copy(baseDir, @"c:\desiredlocation"); throws exception!
Exception type:
IOException
Exception Details:
The target file "C:\desiredlocation" is a diretory, not a file.
PS: I want to copy the exe file namely 'ConsoleApplication1.exe' to C:\desiredlocation and not he entire project.
Any ideas?
|
|
|
|
|
You may want to re-read my answer
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Hi Pete,
The code:
File.Copy(baseDir, @"c:\desiredlocation"); throws exception!
Exception type:
IOException
Exception Details:
The target file "C:\desiredlocation" is a diretory, not a file.
PS: I want to copy the exe file namely 'ConsoleApplication1.exe' to C:\desiredlocation and not the entire project.
Any ideas?
|
|
|
|
|
Hey, I read the documentation for you!
public static void Copy (
string sourceFileName,
string destFileName
)
Parameters
sourceFileName
The file to copy.
destFileName
The name of the destination file. This cannot be a directory or an existing file.
Alan.
|
|
|
|
|
Hmm, copy the currently running executable..... we had another guy here recently trying to achieve the same.
|
|
|
|
|
Copying the current execuable is a very difficult task and indeed a difficult task. I dont care who that another guy was and what he wanted to achieve.
|
|
|
|
|
You are the other guy you twat!
|
|
|
|
|
Why do you have to copy the current executable to another location? What kind of application are you writing?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
This user goes by another name, Rajdeep.Net, who has been repeatidly asking for code or help with intentions to create malicious and/or harmful applications. His previous posts clearly indicate it, and it's undeniable. After so many complaints from users here, he resorted to reregistering under a different name, specifying a different country of origin.
I hate him.
|
|
|
|
|
I had the same doubt as well. I could make it out clearly from the way he forms his query (and also the query itself). Don't give him too much importance to hate him. Just ignore him, he will go away. He has to.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
ShreeR.Bhattacharjee wrote: Check this out guys!
Give your thread a 'meaningful' title.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
public class SomeEnumAttribute: DescriptionAttribute
{
public override string Description
{
get
{
string resFile;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
Type type = assembly.GetType("/*The type defined needs to go in here*/");
if (type != null)
{
resFile = assembly.GetName().Name ;
break;
}
}
}
}
}
public enum MyEnum
{
[SomeEnumAttribute("abc")]
abc = 0,
[SomeEnumAttribute("def")]
def,
[SomeEnumAttribute("ghi")]
ghi,
[SomeEnumAttribute("ghi1")]
ghi1
}
What we ought to do is this: Get the fully qualified name of the enum(MyEnum) and replace it with "/*The type defined needs to go in here*/" in the snippet above.
Can someone help with this.
Note: This class is defined in another binary.
<italics>In another words the question is can we get the enum name(type name) in which the attribute is being used.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
modified on Thursday, June 4, 2009 4:11 AM
|
|
|
|