majnun
asked on
extending an object of a class without making a new class?
I want to extend the functionality of textbox, so that it returns Null if its text is empty instead of an empty string...
however I don't want to create a new extended class, I just want to extend that particular textbox.
Is this possible?
however I don't want to create a new extended class, I just want to extend that particular textbox.
Is this possible?
apologies, thought this was C# initially
Public Property MyText() As String
Get
Dim value As String = Nothing
If box.Text.Trim().Length > 0 Then
value = box.Text.Trim()
End If
Return value
End Get
Set (ByVal value As String)
box.Text = value
End Set
End Property
Public Property MyText() As String
Get
Dim value As String = Nothing
If box.Text.Trim().Length > 0 Then
value = box.Text.Trim()
End If
Return value
End Get
Set (ByVal value As String)
box.Text = value
End Set
End Property
ASKER
I don't want to create a new property, I want to change how the textbox.text property works... also I need to change it during run time, such as while looping through a collection of controls.
Thanks!
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is this in relation to data-binding to a database? You want the table field to be Null instead of an empty string, right?
Bob
Bob
ASKER
TheLearnedOne
You really are learned, that is exactly the reason.
So what do i do?
You really are learned, that is exactly the reason.
So what do i do?
How are you accessing the database? Do you have any code to highlight?
Bob
Bob
ASKER
My code is dynamically created, spread over a bunch of functions in a class... its really clever but messy to look at if you don't want to pour over hundreds of lines of code...
Essentially:
I am using oledb connection to access database
I am creating adapters for each related table
I create commands using commandText with parameters
I am creating a primary key column for each table that corresponds to an autonumber primary key
I fill a dataset from each of the adapters i have created
I create datarelations between the tables in the dataset
I bind controls to columns of particular tables in the dataset.
I use form's binding context to move through the dataset table
If you really really want to see the code i'll post it, but the above info I'm hoping will suffice.
Essentially:
I am using oledb connection to access database
I am creating adapters for each related table
I create commands using commandText with parameters
I am creating a primary key column for each table that corresponds to an autonumber primary key
I fill a dataset from each of the adapters i have created
I create datarelations between the tables in the dataset
I bind controls to columns of particular tables in the dataset.
I use form's binding context to move through the dataset table
If you really really want to see the code i'll post it, but the above info I'm hoping will suffice.
Does the DataAdapter have an UpdateCommand?
Bob
Bob
ASKER
You betcha.
ASKER
Update command with parameters (if it matters).
I am fresh out of ideas. I can't seem to find any way around this.
Bob
Bob
ASKER
Yeah, I tried changing the value of the field to dbnull.value during the RowUpdating event of the adapter, but it seems that doesn't work because by the time the adapter is updating the column has a type of string, and I can't change that, and it seems to convert dbnull.value to an empty string anyway.
It just seems odd to me that MS didn't address this directly, since Access is one of their programs and , and people without $ for SQL server use mdb files. Oh well.
So, then I guess I'll just make all the fields allow zero length string, or extend the controls to return null instread of an empty string.
And b1xml2 is correct? You can't modify an instanced object's members during run time?
It just seems odd to me that MS didn't address this directly, since Access is one of their programs and , and people without $ for SQL server use mdb files. Oh well.
So, then I guess I'll just make all the fields allow zero length string, or extend the controls to return null instread of an empty string.
And b1xml2 is correct? You can't modify an instanced object's members during run time?
ASKER
I mean add/remove/or modify how their public methods behave.
That is correct AFAIK, that you can't modify members during run-time. There might be some "magic" code in CodeDOM, or Reflection, but I don't have any specific knowledge to that effect.
Bob
Bob
ASKER
Ok, well I'll close out the question and award points b1xml2 since he was the first to answer the question posed.
Bob:
I appreciate your help on the particular matter driving the question, and if you have further insight into that problem please post at:
https://www.experts-exchange.com/questions/21388792/VB-NET-Access-mdb-file-Nullable-fields-with-Allow-Zero-Length-Strings-set-to-false.html
I accidentally closed that question because I tested it incorrectly and it seemed to work when it really didn't, and if you want points for your answer I can just open another question for you to answer.
Thanks all!
Bob:
I appreciate your help on the particular matter driving the question, and if you have further insight into that problem please post at:
https://www.experts-exchange.com/questions/21388792/VB-NET-Access-mdb-file-Nullable-fields-with-Allow-Zero-Length-Strings-set-to-false.html
I accidentally closed that question because I tested it incorrectly and it seemed to work when it really didn't, and if you want points for your answer I can just open another question for you to answer.
Thanks all!
private string MyText
{
get { return box.Text.Trim().Length == 0 ? null : box.Text.Trim(); }
set { box.Text = value; }
}