|
In order to test for a null within a DataTable Column I use
DataRowView corrAddress = (DataRowView)debtorBinding.Current;
if (corrAddress["PostCode"] != DBNull.Value)
{
corrPostCodeTextBox.Text = corrAddress["PostCode"].ToString();
}
But
if (debtorDataSet.Debtor[0].HouseName != DBNull.Value)
{
corrHouseNameTextBox.Text = debtorDataSet.Debtor[0].HouseName.ToString();
}
does not work. How can i correct the second code snippet to work please?
|
|
|
|
|
if (String.IsNullOrEmpty(debtorDataSet.Debtor[0].HouseName))
I are troll
|
|
|
|
|
Thanks, but my data is DBnull not null. How can test for this by altering
if (String.IsNullOrEmpty(debtorDataSet.Debtor[0].HouseName))
please?
|
|
|
|
|
Hi to everyone...
Can anyone help me?
I have a small desktop application build in C#. It should create an XML file (already done this), and then enter the xml file in db, in the correct tables. For example,
xml file has this:
<name>John
<info>OtherData
now this file shoud be opened, and read all information, and entered in db, in the respective tables, for example name should be entered in tblCustomer, info should be entered in tblInfoCustomer...
All the Best..
KppsK
|
|
|
|
|
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
|
|
|
|