|
I haven't even dipped my toe in the ADO water yet, but even so, I thought I would bounce this idea off you guys.
I have an object which contains 50 or so properties, of varied types likes strings, integers and the odd enumeration. I am getting pretty sick of the fact that everytime I think of a new property that can go on my object I have to write property acessors and then modify the database layout and then modify all the functions which add, delete and modify records.
I am working on a method that, so long as the columns in my table bare the same names as my properties I can enumerate the list of properties on an object and load the value for that property by fetching if from the .Items collection of a data record using the property name as the column name.
This means as soon as I add a new property and a new column my code effectively adapts to ensure that column or property are always loaded, saved or updated, without me having to modify any CRUD (create, read, update, delete) statements.
You are gonna tell me ADO does this and makes you coffee and predicts all the properties you want on your object using the ADO.CrystalBall.SeeFuture interfaces aren't yah!?
What do you think of the idea. I also thought it might be useful to create a new attribute which would exclude properties that you do not want to have handled in this way.
Thoughts and input, or other nice to haves are most welcome, as is all the scorn that this idea will create hahaha 8-)
Nursey
|
|
|
|
|
It works like a dream....
I just completely integrated this approach into my VisualTheme project, which serialises heaps of color information into an Access database.
Whenever I call my AutoBuildSQL function it returns a sql statement which satisfies the columnname=fieldvalue syntax of a SQL UPDATE statement.
This means I no longer have to write a function to specifically create a sql statement with all the column names and associated values, I just call my AutoBuildSQL statement and it returns a SQL statement with all the property names as SQL column names followed by an "=" followed by the property value...
Here's an example call....
Public Sub UpdateTheme()
If Not mConnection Is Nothing Then
Dim lCmd As System.Data.OleDb.OleDbCommand = mConnection.CreateCommand()
Dim lsSQL As String = AutoBuildSQL()
Try
lCmd.CommandText = "UPDATE Themes SET " + lsSQL + " Where Name = '" & Name & "' "
lCmd.ExecuteNonQuery()
Catch Fail As Exception
MsgBox(Fail.ToString & Chr(13) & Chr(13) & lCmd.CommandText, MsgBoxStyle.OKOnly, "UpdateTheme")
End Try
lCmd.Dispose()
End If
End Sub
The only caveat is that my real code doesn't save any properties that exist in the "THEME" property category (you know that wonderful attribute you can assign to properties). So as I said in my previous post, I should really create a new attribute called "AutoSQL" which will include the associated property in my automated data handling method, otherwise the property will be disregarded.
If this makes any kind of sense to you guys, and I hope it does, coz you are far better and more experienced than me at this stuff, then let me know if you think this is a good idea then I'll create it as a proper OO approach and generate a new article to post on here for all those interested parties to download and reuse.
Thanks for reading.
Nursey
|
|
|
|
|
Sorry to keep posting on and harping on, but I'm just getting so many good feelings about this approach. Even though its pretty simpistic, the amount of coding time it saves is pretty significant.
I am going to extend the idea so that it can automatically create tables in a database that match the layouy of the object, i.e it will create the appropriate columns with the matching types and data lengths as the properties on the object.
My Theme object now barely has a need to know anything about the database to which it is linked, which makes me feel pretty good as it can be changed by people to use SQL Server, Access, XML or text files with very little effort.
Nursey
|
|
|
|
|
Hi,
Is there any one to help me out using of Comm events in .NET.i just want to know which event .NET is equilant to "OnComm" event in VB6.or else tell me where exactly i would be able to get more info about Comm ,as .NET books are not covering this area.I would be eagerly waiting for some kind of help..
pls
|
|
|
|
|
If you are trying to use the Serial comm, for serial communication, I download a lib. that you can use just, tell me and I will sended to you.
ElRaptor
|
|
|
|
|
Hello Shihab:
I thing you are missing a line you need tell the library to read from the port and how many bytes your reding, this is the part of the code I am using to read:
Dim Cadena as string
' As long as there is information, read one byte at a time and
' Save it.
While (ObjComm.Read(1) <> -1)
' Save data read
Cadena = Cadena + Chr(ObjComm.InputStream())
End While
First I check If there is information to read and I tell the function to read only one byte, then I read the byte and I add the Character to a string.
You are using the InputStreamString, and if you look in the code this function uses the InputStream function to read each byte, I havent use this Property but I thing that you need to define the quantity of bytes to be read.
Hope this helps
JA
PS: Happy New Year!!!!!!
|
|
|
|
|
Hi all, hope you are having a bug free weekend!
I have attempted to write a function which scales and translates a graphics path.
If you describe a path as a square, I want to be able to draw your path twice...the first time using the size you specified in the path, then the second time I want to move it and reduce it (scale it down) by a specific number of pixels.
I attempted to write code to do this, but I fear my limited mathematical abilities are whats causing me to see rather odd results in size and position.
The thing is I DO NOT want to reduce the second drawn path by a percentage. I want to move it in by X,Y pixels then of course reduce its width by X*2 pixels and Y*2 pixels, so that the second shape always stays centralised with respect to the first. What this would mean is that I can have user defined button shapes, where I can maintain somekind of consistent look with pre-programmed rectangular and circular buttons which have gradient filled borders.
Can anybody offer me some code which produces a matrix that causes a translation and appropriate scaling factors to produce the required results? I think I only need the code to set the appropriate matrix properties, so you don't need to give me a big story. I will look at your code and probably see where my own is lacking.
Thanks in advance.
Nursey.
Nursey
|
|
|
|
|
I'm writing a macro that will tansfer information from a form in a Word documet to an Access database. I have parsed all the information I need into strings, and have found the automation commands for opening the Access database, I cannot figure out where to go from there.
Do I open a form in Access and use the form's controls to set the text of the textboxes? I cannot figure out how to set the point for the form or control from the Word macro. Is there a better way to do this?
|
|
|
|
|
Ok,I got this figured out you have to check the Microsoft Access 9.0 Object Library in the tools/references.
|
|
|
|
|
hello friend...
just send me any mail id so that i can send u the zip file....that might solve ur problem
With Regds
Vipin Bokariya
|
|
|
|
|
I normally code in C#, but I'm currently using VB.net for one of my projects. I have the option "Allow me to edit VB source code files while debugging" checked, but cannot do so. I get the message "Cannot currently modify this text in the editor. It is read-only." Does this feature not work with VB.net? Than doesn't seem likely, since the option is given. I do not have the same problem when using C#.
What am I missing?
Charlie
Here I am. Love me.
|
|
|
|
|
I'm using VS 2K3 and don't have that problem. All I did was check the Tools/Options/Debugging/Edit and Continue/'Allow me to edit VB source code files while debugging' box, restart VS and everything worked! BUT!!! It will only allow you to edit the files during a breakpoint! You can't edit the files while your code is actually running. You have to stop the code at a breakpoint first.
RageInTheMachine9532
|
|
|
|
|
Thanks for the response.
That's a little disappointing. I'm used to being able to edit the source code whenever I please, no matter the state of the app.
Oh well, such is life, I guess.
Charlie
Here I am. Love me.
|
|
|
|
|
I can open up to 5 Webbrowser controls on 5 separate forms. A medium size panel control on each form is transparent. I can only open up to 3 forms before memory is exhausted. As a test, when I eliminate the transparency I have opened the same form up to 50 times without any problems.
Has anyone else run into this problem using the TransparencyKey? I can’t find anything at MS on memory consumption and the transparencyKey property.
Thanks, GregC
|
|
|
|
|
as topic, if i wan to create an array where the content of the array can be edited by form1 and form2, how i going to do it?
for example the content of array is {1,2,3}
form2 change the content to {1,2,4}
form1 also can see the changes in the array
where i should declare the array and wat is the format?
and how am i going to call the array in form1 and form2 for modification?
any help is greatly appreciated...thz...
|
|
|
|
|
how t to draw 3D or 2D charts in VB.net programatically.
i know how to draw it by adding it at design time.
Nothing ...........................................................
|
|
|
|
|
as topic, how do i check the data type (integer and string) of the user input in a textbox??
if i wan the user to input number 123, but he/she entered 123A, how i going to detect there is an error of input?? any help is greatly appreciate...
|
|
|
|
|
Try something like:
Dim MyInteger As Int32
Try
MyInteger = Convert.ToInt32(Me.TextBox1.Text)
Catch fex As FormatException
' Do something here to handle the input being wrong
' like "123A"
Catch oex As OverflowException
' Do something here to handle the input being out of
' range (i.e. It is a number but is it too big for
' an 32 bit integer.
End Try
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
thanks again for help
this solution is works for checking integer, but seems like doest work on character?
i need to check a user input whether it is charecter type...
ur help is greatly appreciated...
|
|
|
|
|
Sorry, I'm don't quite understand. I thought you wanted to check that the input was an integer. Is this another control you want to check? Can you be more specific about what you need it to do.
Thanks.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
One way to validate user input is using regular expressions. Regexes can get pretty complicated if you need them to do more advanced validation, but simple things like making sure only numbers are input are simple enough.
This test looks for the beginning of a line, followed by one or more numbers, followed by the end of the line:
Imports System.Text.RegularExpressions
<br />
Dim re as new Regex("^\d+$")<br />
If re.IsMatch(myTextBox.Text) Then<br />
'Input passed the test<br />
Else<br />
'Failed<br />
End If<br />
To accept only non-numbers: "^\D+$"
To accept only strings in the format 123A: "^[\d]{3}[A-Z]$"
There are more variations than you can shake a stick at. You could, for example, make sure input is in the format of a US social security number or a phone number or a URL or whatever else you can think of.
Charlie
Here I am. Love me.
|
|
|
|
|
thanks for help
what if i wan to accept only character A-Z and a-z ?(no included symbols such as @#*%_)
wat is the regularexpression format?
To accept only non-numbers: "^\D+$"
this format accept only character but it also accept symbols which i dun wan be included...
ur help is greatly appreciated...
|
|
|
|
|
Anything in square brackets will match one character. The hyphen specifies a range. For example, [a-m] will match 'a' or 'g', etc., but not 'n' or 'A' (It's case sensitive, although there's an \i switch to compare in a case insensitive manner.) So [a-zA-Z] is what you're looking for. \w is similar, but also matches _ and 0-9
Mastering Regular Expressions[^] by Jeffrey E. F. Friedl is a great book about regexes. The author uses perl for the bulk of the book, but there is a section specific to .net and .net uses mostly perl flavored regexes, anyway. (Though in an OO way). If you don't use them enough to justify purchasing a book, VS.Net's online help has quite a bit of info on them.
Charlie
Here I am. Love me.
|
|
|
|
|
the default setting of combo box enable user to edit the listed in combobox just like normal textbox, but i cant find any property that can disable this option, i wan the combobox to be read-only to user...how i going to do that?? anyone can help me??VB.Net
|
|
|
|
|
Try this:
Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Or just set it in the designer.
The defintions for ComboBoxStyle are:
DropDown The text portion is editable. The user must click the arrow button to display the list portion.
DropDownList The user cannot directly edit the text portion. The user must click the arrow button to display the list portion.
Simple The text portion is editable. The list portion is always visible.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|