|
Parse the XML file for the values that you are looking for then create an SQL statement that takes the values as its parameters and inserts them. Look up SqlCommand on msdn, there are plenty of examples.
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
Is the problem in extracting the information from the XML file? If that's the case, you could use XmlDocument[^] class, load the data into it and then extract the info you want. After that, using parameterized commands, insert/update the data into the database.
|
|
|
|
|
Hello,
Can We create dynamic enums at runtime instead of statically creating a class
a enum class like
public enum IceCream
{
[DescriptionAttribute("Choco Chip")]chocochip= 0,
[DescriptionAttribute("Butter Scotch")]buttersoctch= 1,
[DescriptionAttribute("Vannila")]vanilla= 2
}
something of this sort.
i ll appreciate any help on this
Thanks,
Mamtha
|
|
|
|
|
Have you tried it? Most of the rest of us that don't know would have to...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
ofcourse i did try , but with no result hence i am putting it down here
|
|
|
|
|
You can create code in memory at runtime and compile it into an in memory assembly. This can be done with the System.CodeDom and Microsoft.CSharp namespaces. You would then use reflection (System.Reflection ) to interact with the assembly. I've seen articles that talk about scripting implementations that give examples of using the classes in the aforementioned namespaces. I've been able to dynamically compile text that is syntactically valid C# code into an in memory assembly and use reflection to execute the code and return a result. So, you should be able to use the same approach to create an Enum in an in memory assembly and then load an instance of the Enum from that assembly. There probably won't be code out there that does exactly what you are asking about, but there is stuff out there that will get you in the ballpark.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
MSDN[^]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
If you think you have to do this, you really need to rethink your design and use an appropriate collection instead.
|
|
|
|
|
well i did had a look at that earlier but really cudnt make it work.
yeah i think enums are always a tough list to be choose, but i couldnt use lists as effectively as enums did. may be i shud just try dig in deep into lists
|
|
|
|
|
Dave Kreskowiak wrote: If you think you have to do this, you really need to rethink your design and use an appropriate collection instead.
I disagree with that statement. I have an utility application that talks to several different tools that all use the same protocol. Rather than having to write custom code for each new tool that may be created, I made a text file format that describes the commands for each tool. Since some of the command parameters are best represented as choices in a ComboBox, dynamic enum creation was the way to go.
To the OP, when making dynamic types you can put spaces and other special characters in the type names, property names, enum names that a standard compiler would not allow, which may prevent the need for the Description attributes on the enum values. Below is the snippet from the utility described above. The prefix was a string like Enum.CommandName.PropertyName and the ParamDef class contained enum type name and the list of enum name/value pairs in the Values property. _module is a ModuleBuilder created earlier to contain all the dynamically created code.
Private Shared flagsCon As ConstructorInfo = GetType(FlagsAttribute).GetConstructor(Type.EmptyTypes)
Private Function CreateEnum(ByVal prefix As String, ByVal param As ParamDef) As Type
Dim eb As EnumBuilder
eb = _module.DefineEnum(prefix & param.Name, TypeAttributes.Public, GetType(Byte))
For Each ev As EnumValue In param.Values
eb.DefineLiteral(ev.Name, ev.Value)
Next
If param.IsFlags Then
eb.SetCustomAttribute(New CustomAttributeBuilder(flagsCon, New Object() {}))
End If
'save the type
Return eb.CreateType
End Function
|
|
|
|
|
I agree it's a requirement when writing code generators, but I seriously doubt that's what he's doing.
Usually, you won't see this question in the forums because the person who really does need this technique is already knowledgable enough to write it up without asking any questions.
|
|
|
|
|
Yes, but why? What would you then do with it?
|
|
|
|
|
Dynamically use the enums, of course.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
Smile when you say that.
But in what way? I don't see what can be accomplished with an enum dynamically.
Usually when I have an enum, I refer to it in a switch or as a parameter to a method; how can that be done dynamically?
Otherwise a Dictionary or HashSet may be a more appropriate solution.
|
|
|
|
|
</sarcasm>
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
|
To be fair I was intentionally trying to reel you in with that which is why I originally left off the smiley.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: reel you in
In which context; like a fish or like a dog?
|
|
|
|
|
Hello,
i have a pictureBox. When i moving the mouse in the pictureBox, i want to draw a rectangle on the bitmap (that is on the pictureBox). I using the DrawRectangle-method for this. But i like, that there appears only one rectangle on the pictureBox. It should appear on the coordinates, where i moving the mouse at the moment. On this moment all rectangles are paintet on the pictureBox, at the coordinates where i have moved the mouse.
Thank you very much!
|
|
|
|
|
It sounds like you're getting multiple mouse moves and therefore multiple rectangles. You'll need to determine when the mouse has stopped moving (maybe a timer that is reset on each mouse move) and draw the rectangle then.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
you looking for a click drag style drawing?
if so then make a global rectangle, on mouse click set the .X and .Y locations of the rectangle. then with mouse mouse set the width and height of the rectangle based on the current mouse pos and the rectangle .X and .Y locations (mouse click point)
Then handle the onPaintEvent to draw the rectangle.
Oh you will need to force the picture box to repaint with each mouse move, i think PictureBox1.Invalidate() can do this for you
|
|
|
|
|
I am developing a windows application using c#. In this Application i need record some sensitive data such as user name and password. In this application i am not using database. Please tell me a way to manage these data in secure way. Please help me this is very argent.
Dushan Perera
|
|
|
|
|
What are the username and password used for?
If just logging in then you can create an MD5 hash and store as that.
if you need to be able to recall usernames/password then look at encryption
|
|
|
|
|
Encrypt the data before saving it to a User Settings file. Also, before distributing your application, make sure you obfuscate it with a decent obfuscation tool (the one that comes with VS is NOT adequate).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
The answer mainly depends on the architecture of the application. Will it be used by many different users that aren't on the same network, or within a local Intranet? What resources will be available to your application to hold that data? You'll have to take those considerations into account in order to determine what is the best option for persisting the data. Regardless of your choice, you are going to need persistent storage of some format to hold the data. Whatever option you decide to go with make sure you store a hash of password values. Personally, I use the .NET MD5 implementation (MD5CryptoServiceProvider) to hash passwords, but the .NET Framework includes a number of hash algorithm implementations. In practice, you should persist the hash rather than the actual password and when authenticating, you take the hash of whatever the user enters and compare it against the hash that was persisted; if it matches then they entered the correct password. It's not mathematically possible to get the original value from a hash. If you need to secure other data you can use some of the other .NET Cryptography classes to encrypt the data. Either way a number of Symmetric encryption algorithms (aka Secret Key) are included in the .NET framework (the .NET Rijndael implementation is what I usually use). You'll generally need to create your own binary Key and Initialization Vector (IV, for short and commonly referred to as the 'Salt'). The Key and IV lengths vary somewhat for the different algorithms so you'll need to read up on that as you decide on an encryption scheme that works for you. Symmetric encryption requires the same Key and IV be used for decryption as was used to encrypt the data, so it's common to choose a Key and IV for your application that are pretty much static. If you need more flexibility than that you can look into the Asymmetric encryption (aka Public key/Private key) but those generally require more complexity, however there are certainly situations that call for it.
Keep It Simple Stupid! (KISS)
|
|
|
|