|
thanks for nice answer. can you please include a article link sir which show how i can use DbProviderFactory to connect sql server ,oracle, oldedb or use dsn to connect any db.
thanks
tbhattacharjee
|
|
|
|
|
I assume Google is broken for you. Seriously, you have been posting on this site long enough to indicate that you are meant to be a professional programmer. Part of being a professional programmer is having the ability to do research for yourself.
This space for rent
|
|
|
|
|
Too bad ... You were doing so well up to this point. You seem to think noone has anything better to do than run down errands for you.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
A simple example of using DbProviderFactory can be found here[^]. Since you already worked with databases I'm going to assume that you'll recognize most parts; note that we ask the Factory to create a connection for us, instead of creating one ourself.
The factory can also create IDbCommands, but I prefer to use the factory-method that is provided in the IDbConnection-interface. Details on the class can be found on MSDN[^].
The factory does NOT make your code database vendor-independant - it just makes it easier to switch between those classes. Your C# code would no longer depend on a specific implementation, but chances are that you are using an SQL dialect that is specific to the database-server. Stick to SQL92 if you want to minimize the risc of incompatibilities.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I'm trying to load a config file from a location other than the app.
// Get the full path and name of the app's Config file.
var configFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
This returns '.....\bin\Debug\OQRangeDataInput.exe.Config', which is correct
Then I do this to load the config file
_configuration = ConfigurationManager.OpenExeConfiguration(configFileName);
The next line, the OpenExeConfigation sets a property on the Configuration called FilePath which is set to '.....\bin\Debug\OQRangeDataInput.exe.Config.config'
this is clearly wrong.
I had to add this right after the first line to fix it
configFileName = configFileName.ToLower().Replace(".config", "");
So, all told, I now have this
private void LoadConfigFile()
{
var configFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
configFileName = configFileName.ToLower().Replace(".config", "");
_configuration = ConfigurationManager.OpenExeConfiguration(configFileName);
AppConfigFile = configFileName;
}
Anyone see what's wrong? Is this some kind of bug, or am I just doing it wrong?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Have a look at the documentation:
exePath: The path of the executable (exe) file.
The method expects you to pass the path of OQRangeDataInput.exe , not the path of the config file you want to open.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well there ya go!!
I was using "AppDomain.CurrentDomain.SetupInformation.ConfigurationFile" because if the Config file doesn't exist I create it.
Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I've recently read about the Inversion of Control (IOC) principle and I have a few questions I'd like to have answered. I've read that in order to implement the principle of IOC, one must not define a class and pass in concrete objects as its constructor's parameters but one must instead use interfaces as its constructor's parameters.
My first question is can I implement IOC by defining a class with virtual classes as its constructor's parameters instead of interfaces. After all the whole reason behind using interfaces is to decouple the class from its dependencies and virtual classes can pretty much do that.
My second question is can I use abstract classes as the parameters instead of interfaces.
Thanks in advance for your reply.
modified 3-Apr-17 3:37am.
|
|
|
|
|
C# doesn't support the concept of virtual classes so, in the context of this forum, the first part of your question makes no sense.
With regards to using abstract classes, yes you can. Only a very poor IoC framework wouldn't support them but there are things to consider. First of all, we tend to prefer composition over inheritance nowadays, so an abstract base class would be a violation of that principal. Versioning an interface is difficult to do, so if you need to inject something that is version aware, you should consider using an abstract class in that case.
This space for rent
|
|
|
|
|
Hi thanks for replying. I meant to say a generic class that has virtual methods or methods that take generic types T.
|
|
|
|
|
Again, you can pass in a generic class to most IoC containers. As soon as you introduce virtual methods, you are getting back to the argument about preferring composition over inheritance again.
This space for rent
|
|
|
|
|
I'd like to add to Pete's correct answer that your question actually deals with two concepts: the inversion of control on one hand, and abstraction on the other hand.
The abstraction is the part where it comes to (abstract) base classes or better interfaces instead of concrete classes: you can use many other concrete implementations later on.
The inversion of control principle is about the question of how to get a class one depends on. If A requires a B for some tasks, it is not the responsibility of A to create B, rather someone else should provide B for A (inject a B into A). While that can be done also with a concrete definition of B, a more abstract definition (see above) is preferred.
|
|
|
|
|
I don't believe IOC excludes "constructors with concrete objects"; it's simply another method of "dependency injection"; which is one of the functions of "IOC".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
modified 4-Apr-17 10:52am.
|
|
|
|
|
IOC does not preclude specifying concrete classes as parameter to be injected in the constructor, although some IOC container implementations my not support this.
The IOC container is basically a super factory that can provide instances of classes or interfaces that have been registered with the IOC container or that the container can determine how to build. The Munq IOC Container, for example, can instantiate concrete classes even if they have not been registered, as long as all of the constructor parameters can be provided from the IOC Container.
In most IOC Containers, you can register a class that, implements either an Interface or a Base Class, to be provided when either the Interface or Base Class is requested.
This means your code now says "I need an instance of class X and I don't care or want to know how to build it, just give it to me" rather than "I need an instance of class X so I'll build up all itsdependencies, and their dependencies to do that. God help me if the dependency hierarchy changes".
"Time flies like an arrow. Fruit flies like a banana."
|
|
|
|
|
In a C# Windows Application Project, On Checking both 2 Check Boxes, a Button Should be Enabled, If any one is Unchecked, Button should be Disabled. Presently ON Form_Load The Same Button should be Disabled.This is working fine.Project Done using Visual Studio 2012.
Please Help me Someone
Prashanth.B.S
|
|
|
|
|
Handle the CheckBox.CheckChanged event: CheckBox.CheckedChanged Event (System.Windows.Forms)[^] - you can use the same handler for both boxes - and check the Checked status of each to set the Enabled property of the button:
myTextBox.Enabled = checkbox1.Checked && checkbox2.Checked;
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Where is your code, what have you done so far?
Relatively simple all you need it to manage the FormLoad and checkbox events.
|
|
|
|
|
Member 13062505 wrote: This is working fine Glad to hear you got it working. Pretty simple, isn't it.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
When I want to add a QRcode to a pdf file with itextscharp and I use the page width for it's position (right corner)
the Qr code is not at the right sight of the page.
Am I missing something?
thank you in advance
|
|
|
|
|
I'm not sure how anyone can help you if you do not post the relevant code.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
HI
I've used this site in the past to code create a jukebox application in c# to control Itunes and play songs from a users library.
I now want to search and play tunes from the store (streaming) using iTunes music. Does anyone know how I can achieve this?
I have the iTunes search api but that just returns an status of
WaitingForActivation
I can search the HTTP site and get loads of info
"https://itunes.apple.com/search?term=the beatles&limit=25 but can't see how to use that from the iTunes com to play it. I've searched the apple developer forum (waste of time) and every other combination of search terms I can think of in google.
Any help appreciated in advance.
Cheers
|
|
|
|
|
Greetings all,
Essentially I am trying to recreate a formula for a column that calculates a cumulative difference between, between differences in data on data from adjacent column on a daily basis. In excel the formula is =ROUND(IF(B4<now(),t4,0),2). does="" anyone="" know="" how="" to="" edit="" the="" method="" for="" computed="" field="" in="" visual="" studio="" achieve="" this?
any="" help="" will="" be="" much="" appreciated<="" pre="">
|
|
|
|
|
You're question makes no sense at all.
There's no calculation going on. All that formula does is compare a date/time in a cell to the current date/time. If it's "less than" now, it returns the value in "T4", whatever that is, or returns 0, rounded to 2 decimal places.
And what do you mean by "in Visual Studio"?? VS doesn't have anything to do with manipulating data. Are you talking about writing this in your own code?
|
|
|
|
|
Hi,
I am new to ASP.NET MVC. I would like to get some help on getting custom data from controller to view.
I have queried and concatenated the result of a table from model based on a criteria. I want this to be viewed as a partial view in the Index page. For this, I pass the queried result as follows
return PartialView(rds.ToList())
The purpose is to display a listview of these items in the Index view as partial. I don't know how to grab this data from the partial view. Please help.
Thanks
|
|
|
|
|
You might get better results if you post this in the ASP.NET Discussion Boards[^] - if you do post it there then don't forget to delete this version
|
|
|
|