|
No problems also be aware that there an Interface is similar to a abstract class in what it may be used for. I don't know your exact requirements but if you don't know about Interfaces then you might want to check them out.
Here is a comparison between Abstract classes and Interfaces which may identify if you could make use of an Interface instead...
Abstract Class versus Interface[^]
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I'm just doing the schoolboy error check, so don't take this amiss, are you sure you haven't really got:
AbsMyObject.MyMethod();
I.E. The method really belongs in the AbsMyObject class rather than the caller?
Also I tried this (to make sure I wasn't about to make a schoolboy error ) and it works without the cast:
public abstract class Foo { }
public class Bar : Foo { }
public class Baz : Foo { }
public class Qux : Baz { }
public class Quux : Foo { }
class Program
{
static void MyMethod(string id, Foo arg) { Console.WriteLine("{0} Called Object Type {1}", id, arg.GetType()); }
static void MyMethod(Foo arg) { MyMethod("Foo", arg); }
static void MyMethod(Bar arg) { MyMethod("Bar", arg); }
static void MyMethod(Baz arg) { MyMethod("Baz", arg); }
static void Main(string[] args)
{
MyMethod(new Bar());
MyMethod(new Baz());
MyMethod(new Qux());
MyMethod(new Quux());
Console.ReadLine();
}
}
Sorry if I misunderstood your problem, but you are right, such if statements have a bad code smell. [Edit]: If those two options don't apply, Pete's suggestion is good. Can MyMethod be refactored to accept the base class and handle the class based differences inside it?
|
|
|
|
|
I think his issue is that he has an object type and therefore doesn't know the actual type of the object and cannot just call the method. For example...
MyMethod(new object());
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I think more complete code from the OP might help. I'm not sure I understand his question in that, I understand the problem that he needs to determine the type for a method call, but I don't know why he doesn't know it in the first place. I read the OP as all the types coming from some abtract base object.
|
|
|
|
|
musefan wrote: doesn't know the actual type of the object
The runtime will.
|
|
|
|
|
This would argue that he either needs an interface, or he needs to use generics instead. Basically, what he has here is a form of class factory, and there are lots of neat implementations that can be used.
|
|
|
|
|
I don't think that's necessary; did you try it without the casting?
But if you do need it, take a look here[^].
|
|
|
|
|
Hi
I'm trying to call a XP Mode shortcut programmatically, but I keep getting the same error message:
"problem starting C:\windows\system32\VMCPropertyHandler.dll The specified module could not be found"
I tried with the following:
string startPath = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup";<br />
Process p = new Process();<br />
p.StartInfo.FileName = startPath + "\\XPModeInitializer (Windows XP Mode).lnk";<br />
p.StartInfo.UseShellExecute = true;<br />
p.Start();
But I have also done many variants. I even tried making a bat file, that just call the link. The bat file itself works when double-clicked, but when called from within my code like the following snippet, I get the same error message:
Process p = new Process();<br />
p.StartInfo.FileName = Environment.CurrentDirectory + "\\CallXPModeInitializer.bat";<br />
p.StartInfo.UseShellExecute = true;<br />
p.Start();
I also tried taking the shortcut parameters and using them myself like this:
string file = System.Environment.SystemDirectory + @"\rundll32.exe";<br />
string arguments = System.Environment.SystemDirectory + @"\VMCPropertyHandler.dll,LaunchVMSal ""Windows XP Mode"" ""||a9c104ed"" ""XPModeInitializer""";<br />
Process p = new Process();<br />
p.StartInfo.FileName = file;<br />
p.StartInfo.Arguments = arguments;<br />
p.StartInfo.UseShellExecute = true;<br />
p.Start();
But it produces the same error message,
I'm confused at to why a direct use of the bat file works, when the call to the bat file from within C# fails!?
How can I call a XP Mode shortcut from within C# code?
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
modified on Wednesday, December 1, 2010 4:35 AM
|
|
|
|
|
System.Environment.SystemDirectory
it self return the "c:\windows\system32\"
why are you aging adding the "system32" in your code ...
System.Environment.SystemDirectory + @"\system32\VMCPropertyHandler.dll,LaunchVMSal ""Windows XP Mode"" ""||a9c104ed"" ""XPModeInitializer""";
Rajesh B --> A Simple Programmer <--
|
|
|
|
|
Bad copy paste. Fixed...
Fixing the System32 part does not make any difference though. It still fails.
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
spif2001 wrote: I'm confused at to why a direct use of the bat file works, when the call to the bat file from within C# fails!?
You could try setting the WorkingDirectory[^];
If the property is not set, the default working directory is %SYSTEMROOT%\system32.
I are Troll
|
|
|
|
|
Sorry sorry sorry... stupid me...
I didn't notice my projects in Visual Studio was set to x86. Setting them to Any CPU solved my problems.
I guess when run as x86, the System32 part of the path gets redirected to the SysWOW64 folder. In which of course the desired files are not placed.
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
spif2001 wrote: I didn't notice my projects in Visual Studio was set to x86. Setting them to Any CPU solved my problems
I would have overlooked that too
I are Troll
|
|
|
|
|
Hey all,
I am not sure whether this is possible and if I am approaching it the wrong way but...
What I'd like to do is have a form that allows 3 separate records from a database to be shown in text boxes similar to:
Record 1 Size Record 1 Rate | Record 2 Size Record 2 Rate | Record 3 Size Record 3 Rate |
Record 1 Total | Record 2 Total | Record 3 Total |
Could someone please push me in the right direction for achieving this? I have a query that returns either 1,2 or 3 records but can currently only get my form to display the same record in all 3 sets of text boxes.
Any help would be appreciated!
Joe
|
|
|
|
|
Without seeing any of your code, it's hard to advise you on how best to do this. Are you binding textboxes directly? Are you programatically binding them? How are you retrieving the data - is it via DataSet or DataReader?
|
|
|
|
|
Thanks for the reply Pete,
I am fairly new to this whole thing - but am slowly getting my head around it.
I'm retrieving the data via DataSet, with the text boxes bound to the dataset(however I have not bound them myself, just dragged and dropped in the designer).
Currently the query I have is a simple designer one with 2 parameters for if ID = @ID1 or if ID = @ID2.
Joe
|
|
|
|
|
i add data set &
add 4 table in this data set and design 4 reports for each table
i want to choose the report & set datasource to report and show in microsoft report view
i try this code but failed
ReportOfEng.LocalReport.ReportEmbeddedResource = "follow_up.Report1.rdlc";
ReportDataSource ds = new ReportDataSource();
ds.Name = dataSet11.Movements.TableName;
ds.Value = dataSet11.Movements;
ReportOfEng.LocalReport.DataSources.Clear();
ReportOfEng.LocalReport.DataSources.Add(ds);
this.movementsTableAdapter1.Fill(dataSet11.Movements);
this.ReportOfEng.RefreshReport();
then in runtime when i btnclick
this message appear in report
"data source instance has not been supplied for dataset"
so what i can do
|
|
|
|
|
Well, LocalReport.DataSources has been cleared, and yet you haven't done a LocalReport.DataSources.Add .
|
|
|
|
|
i add the datasource in program but i forget to add in this block code
so the error appear in the report
so again what can i do
|
|
|
|
|
depend on RadioButton Check
if (rdbEng.Checked==true)
{
ReportsOfRun.Reset();
ReportsOfRun.LocalReport.ReportEmbeddedResource = "follow_up.Report_Eng.rdlc";
ds.Name = "DataSetReport_Eng_Table";
ds.Value = Eng_TableBindingSource;
ReportsOfRun.LocalReport.DataSources.Add(ds);
ReportsOfRun.DocumentMapCollapsed = true;
this.Eng_TableTableAdapter.Fill(this.DataSetReport.Eng_Table,int.Parse(txtEngCode.Text));
}
else if (rdbMonth.Checked==true)
{
ReportsOfRun.Reset();
ReportsOfRun.LocalReport.ReportEmbeddedResource = "follow_up.Report_Month.rdlc";
ds.Name = "DataSetReport_Month_Table";
ds.Value = Month_TableBindingSource;
ReportsOfRun.LocalReport.DataSources.Add(ds);
ReportsOfRun.DocumentMapCollapsed = true;
this.Month_TableTableAdapter.Fill(this.DataSetReport.Month_Table, txtMonth.Text);
}
thanx to how try to help me
|
|
|
|
|
Well done, and well done for showing your solution. That's a bit of class that is.
|
|
|
|
|
i call this method by button and this exception appeare
exception "Backup failed for Server"
public void BackupDatabase(String databaseName, String destinationPath)
{
Backup sqlBackup = new Backup();
sqlBackup.Action = BackupActionType.Database;
sqlBackup.BackupSetDescription = "FollowUPBackUP:" + DateTime.Now.ToShortDateString();
sqlBackup.BackupSetName = "FollowUP";
sqlBackup.Database = databaseName;
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
string instantname = @".\sqlexpress";
ServerConnection connection = new ServerConnection(instantname);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlBackup.Initialize = true;
sqlBackup.Checksum = true;
sqlBackup.ContinueAfterError = true;
sqlBackup.Devices.Add(deviceItem);
sqlBackup.Incremental = false;
sqlBackup.ExpirationDate = DateTime.Now.AddDays(10);
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
sqlBackup.FormatMedia = false;
sqlBackup.SqlBackup(sqlServer);
}
modified on Wednesday, December 1, 2010 1:17 AM
|
|
|
|
|
I'm pretty sure that the error message was longer than just "Backup failed for Server". If it was then it might help people, to help you, if you edited your question to include the full message.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
Why would you want to do this?
|
|
|
|