I am using VB.net in creating this application. My idea is when the main form loaded, there is another form with textboxes for the user to initialize connection to the sql server, and use that textbox value in calling the database for query.
Now, my problem is then main form closes the value in the textbox will be erased, and i have to type it again. When connecting for an SQL Server over the LAN, does it have the same process?
You should not be referencing controls' values for logical uses like that; instead use the value in the control to populate a more persistent program entity, such as a settings object.
In your particular case, with VB.net (and presumably WinForms), showing connection form with ShowDialog() allows the form to persist after it has been closed. You can add a public property to the form to expose the user-entered value to the code that called it, and DialogResult of OK when the user indicates the value is accepted (usually through a button click).
I'd provide a code example, but I've been deep in C# for more than a few months now and my VB.Net is getting rusty.
Related
I would like to know if it is possible in a Saved Query on MS Access to use WHERE clause getting value from a Form independent of MS Access installed language?
In a MS SQL QUERY WHERE clause that should be equal to a text in a form, I wrote it like this
= Form!Form_name!text_name
This work fine if all user have MS English version installed, however, this is not true in my case, as some users have a Portuguese version. In their version, the right way to call the same syntax should be:
= Formulários!Form_name!text_name
So, the problem is that Access does not recognize this considering language version. Due to this, if a user with Portuguese version try to run the query, it will pop up an insert box.
I've look throughout many sources but none could help me to solve this.
Thank you all in advance!
I can't test this as I don't have a portuguese version of Access but I avoid calls to form parameters because they are brittle. For instance the form has to be open or the query fails in wierd ways. If I must use a form's parameter I wrap the parameter in a public function (usually in that forms code behind). A public function usually gets picked up by intellisense even in the designer but a public variable does not.
My style is to synthesize a property with a private global scope variable and public get and set functions. Then in the designer you can call: get-myforms-property instead of Form!Form_name!text_name. When the form opens and closes I usually call set-myforms-property and set it to be equal to the actual form property.
In this way you also get the advantages of wrapping. For instance you can choose what value to return when the form is closed rather than just having the query fail.
I am currently updating an MS-Access legacy project. In a form I want to bind some controls to VBA properties (Property Let and Property Get), similar to the way it is done in WPF. Is this posssible? We are using Access 2007.
The ControlSource of a control can be a function:
=MyFunctionReadingSomeProperty([SomeParameter])
so if you can manage to build such a function, the answer is Yes.
However, the function is read-only, so if you want to set a property, the function must be able to do that using one (or more) parameters.
If you omit the parameter:
=MyFunctionReadingSomeProperty()
the function will be called only once, when the form loads.
First off, I've done a lot of research on the web (including this site) and have found lots of conflicting information on how the model and controller communicate in an MVC pattern. Here is my specific question (I'm using AS3), but it's a general MVC question...
I have two main components... a list of recipes and a form that displays a selected recipe. The form has an edit state that allows you to edit the recipe and then save or cancel the changes. What is the best way (using MVC principles) to handle changes made to a recipe? So far, I have the save button trigger an event which is captured by the controller.
Should I have the save button (the view) pass an object with the current state of the fields along with the event (some logic in view)? Should I allow the controller to hold access to the view and have the controller figure out what's in the fields on its own (added coupling)? Should events be made every time a field in the form is changed and the controller keeps track of the state of each field (lots of events)? Or is their another way? Note: I don't want to bind the fields to the model because I only want the data to save if the save button is clicked.
Any help would be greatly appreciated. Thanks!
Should I have the save button (the view) pass an object with the
current state of the fields along with the event (some logic in view)?
yes, this is not 'logic in the view', it does not decide anything, simply reporting an action and its current state
Should I allow the controller to hold access to the view and have the
controller figure out what's in the fields on its own (added
coupling)?
no, this would become very messy, pass a VO with the event
Should events be made every time a field in the form is changed and
the controller keeps track of the state of each field (lots of
events)?
is an option, but this basically is the same as hitting the save button, the trigger is different (TextField.onChange), but you can dispatch the same event (setup is form = view, dispatches one general event with a VO, not an event for each field)
Or is their another way?
MVC flow w/ events:
onClick save btn: a RecipeEvent.SAVE is dispatched (from the view), with a VO (value object) containing the Recipe data (e.g. RecipeVO)
the controller catches this, and as the controller is where the logic resides, it decides what to do with it: update the RecipesModel (either directly by calling a method on the model, or by a custom event e.g. RecipeModelEvent.SAVE)
the model stores the data, and dispatches the RecipeEvent.UPDATE event (with the RecipeVO)
the views updated itself accordingly (check if the RecipeVO.ID is same, update data representation e.g. title…)
optionally, a controller could save the data to a back-end/remote database
As for the event listeners: views listen to the model, controller listen to the views.
About de-coupling:
use interfaces (by using an IModel you can swap out the model easily by another implementation, as you register the event listeners against the interface instead of the actual implementation)
Obviously, all this results in a lot of registering/removing event listeners, and keeping reference to the models/views/controllers to be able to register to the appropriate instance. An alternative is to use a framework as RobotLegs, as it makes a central event-bus available + easy/automatic cleanup of event listeners in the mediator class of a view.
I think this is really a database question. what I would do is create a stored procedure that first checks to see if the recipe already exists. If yes then update it. If not then add a new recipe. (you'll have to bind your entity to a stored procedure. other MVC frameworks can do this. I don't know about actionscript)
if that's not an option then I guess you would have to cache the original form in a helper class in the controller and then compare it to what the user is trying to save. And have the controller decide whether to update the recipe.
I think it's much cleaner to use the first way, but I've never used actionscript so...
Colin Moock's lecture on MVC in ActionScript is quite old, but still one of the best explications: http://www.moock.org/lectures/mvc/
Your model should populate your view, and your view should send input events to the controller, which should decide what to do with the input. As g10 says, wait until the save button is clicked and then pass an object with the modified fields up to the controller for processing. The controller can then decide whether or not to accept it, and whether to update an existing model object or create a new one.
I have a Access 2003 database that will dynamically load MDB databases as a library reference. The reason for this is this database is a menu front-end for 60+ application databases. Rather than deal with permanently referencing all these databases, the menu front-end will dynamically reference what is needed when the user makes a selection. I was working on moving this database to Access 2010 and creating a custom ribbon. I started using the technique from here to capture the ribbon object in a global variable when the ribbon loads. I then ran into the problem where I could verify the code was running and the global variable was correctly being assigned the ribbon reference but after the database would run through it's startup routine, that global variable would get reset to Nothing.
To verify what was going on, I created a simple database for testing. In this database, I had a module with a global variable:
Public obj as Object
I then had a function like this:
Public Function SetObj()
Set obj = Application
Debug.Print "IsNothing=" & (obj Is Nothing)
References.AddFromFile "Test.mdb"
Debug.Print "IsNothing=" & (obj Is Nothing)
End Function
Obviously, in my code, "Test.mdb" refers to an actual file. If I run this code, Debug.Print gives me "IsNothing=False" for both instances, but after the function finishes and if I wait a couple seconds, Debug.Print will give me "IsNothing=True". If I comment out References.AddFromFile, Debug.Print gives me "IsNothing=False" no matter how long I wait.
It makes sense to me that since Access has to re-compile the VBA code after loading the library that all global variables are reset. I've experimented with moving the global variable into a class, but since I then need a global variable for the class, the class variable then gets reset instead. I tried using a local variable in the function to save the value of the global variable, but it looks like Access waits a couple seconds after the code is finished running to do the re-compile, so that doesn't work either. Does anyone have any other ideas to accomplish this?
I don't really know if this will solve the problem for this kind of reference, but in general, I don't use public variables for this kind of thing, but instead use a STATIC variable inside your function. It would be something like this:
Public Function SetObj() As Object
Static obj As Object
If (obj Is Nothing) Then
Set obj = Application
End If
Set SetObj = obj
End Function
Then you'd just use SetObj as an object for using your application. In a production app, you'd need tear-down code, too, but I've omitted that here.
I doubt this helps, but your code struck me as rather inefficient and incomplete.
I figured out a solution to my problem, and thanks #David-W-Fenton, as your answer gave me the idea. I use your approach in a library database for caching frequently-accessed values that are stored in a table but don't change after the initial startup. Those values aren't lost every time the references change, and that's when the light bulb lit up.
The solution is to put the global variable in a library database. Access looks to be only resetting global variables in the database that the reference is being loaded into - which makes sense after thinking about it. So since the library database isn't the one being re-compiled, it doesn't get it's global (or private or static) variables reset.
What I ended up doing was creating a new module in an existing library database. It has a private variable and two methods - one to set the variable, one to retrieve the variable value. In my menu front-end database, when the ribbon loads and calls my callback function, rather than saving the ribbon object in the front-end database, I pass it to this module for saving. I now no longer lose that ribbon reference whenever new databases are added to the library references on the fly.
I'm using the code found here for Ajax ordered/pagination support for a Seam EntityQuery. The code itself is working great, and I am able to sort my data with no problem by various parameters. The entity itself is not a SQL table, but rather a SQL view mapped to a JPA (Hibernate) Entity. That, too, seems to be working without issue, so long as I stick to SELECT statements and not try to perform an INSERT or UPDATE. My backend DB is PostgreSQL 8.4, and I haven't implemented any conditional TRIGGERs to allow for VIEW update support.
My problem has to do when I go from one page of results to another using the EntityQuery.next() or EntityQuery.previous() methods. It appears the entire page request is wrapped in a transaction, and when I click my next button it attempts to perform an UPDATE on my Entity object. I've overridden the next() method in my EntityQuery and that operation goes through successfully. But, immediately after it finishes and right before the view is rendered the attempted UPDATE occurs. Since my Entity object can't be updated on the backend DB (since it's a VIEW) I get an Exception thrown.
Is there any way to prevent a transaction from being opened when using this EntityQuery? I've tried annotating my Entity object with #ReadOnly. That didn't work. I've tried adding #Transactional(NEVER) to my EntityQuery. That didn't work. Any other ideas?
Try changing to session scope on your component. That way seam will load the object from memory instead of hitting the database.
#Scope(ScopeType.SESSION)