|
Paulo Zemek wrote: This works.
Yes. So does this:
Console.WriteLine(0);
Console.WriteLine(1);
Same outcome, more readable though.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
This does not generate the same result.
I set the i = 0. But consider that i is entered by the user.
Console.WriteLine(0);
Console.WriteLine(1); will not be the same, as in some cases only the case 1 must be executed. As I understand, the idea is to have the option to "start at any point", but continue from it. And I am not saying the solution used is a good one, but it is the easiest to convert a C++ code without really refactoring it.
|
|
|
|
|
Yeah. And then some poor sod (probably me with any luck) gets to maintain the ramshackle heap of spagetti.
Do the job right. If you are converting C++ to C# then convert it to good C#. It may be you who has to "upgrade" it in six months time...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Hi All,
How can we make the dynamic property in windows application in C#,that can pick the list from the database?
Please help,its urgent....
Thanks,
Lalit Narayan
|
|
|
|
|
lnmca wrote: its urgent
Checked the urgent section on my ToDo list and this wasn't on there so I'm afraid you're wrong.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Make sure you call update() on your todo list before checking new items
|
|
|
|
|
I find this works best
public Message UpdateToDoList()
{
toDoList.Nuke();
return new Message("Nothing to do today, lounge around on CP instead");
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
In C# one can use the Process.Start() method to open a file using the default program set for the filetype in the registry. I would like to use the "edit" property in the registry (possibly with fallback on "open"). This can be achieved by setting the Verb-property in the ProcessStartInfo object.
When the user has not set the application to use when editing a certain file I would like to give him/her the opportunity to choose. I have found that this is done by setting the Verb property to "openas". This will give the user the standard windows dialog to pick an application from a list or browse for it in the filesystem. This leads us to my question.
How can I do the same thing for the edit property in the registry? ("editas" doesn't seem to cut it at all)
|
|
|
|
|
hello
i want to know how to backup a database from a distant server using c# and SqlServer2000.
NB:i just succeeded in doing this with a local server.
and here is the code:
[using System;
namespace test_backup
{ public partial class Form1 : Form
{ private static Server srvSql;
public Form1()
{ InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Create datatable where we enumerate the available servers
DataTable dtServers = SmoApplication.EnumAvailableSqlServers(true);
// If there are any servers at all
if (dtServers.Rows.Count > 0)
{
// Loop through each server in the DataTable
foreach (DataRow drServer in dtServers.Rows)
{
// Add the name to the combobox
cmbServer.Items.Add(drServer["Name"]);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
// If a server was selected at all from the combobox
if (cmbServer.SelectedItem != null && cmbServer.SelectedItem.ToString() != "")
{
// Create a new connection to the selected server name
ServerConnection srvConn = new ServerConnection(cmbServer.SelectedItem.ToString());
// Log in using SQL authentication instead of Windows authentication
// srvConn.LoginSecure = false;
// Give the login username
//srvConn.Login ="."; //txtUsername.Text;
// Give the login password
// srvConn.Password =""; //txtPassword.Text;
// Create a new SQL Server object using the connection we created
srvSql = new Server(srvConn);
// Loop through the databases list
foreach (Database dbServer in srvSql.Databases)
{
// Add database to combobox
cmbDatabase.Items.Add(dbServer.Name);
}
}
else
{
// A server was not selected, show an error message
MessageBox.Show("Please select a server first", "Server Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void button2_Click(object sender, EventArgs e)
{
// If there was a SQL connection created
if (srvSql != null)
{
// If the user has chosen a path where to save the backup file
// if (saveBackupDialog.ShowDialog() == DialogResult.OK)
// {
// Create a new backup operation
Backup bkpDatabase = new Backup();
// Set the backup type to a database backup
bkpDatabase.Action = BackupActionType.Database;
// Set the database that we want to perform a backup on
bkpDatabase.Database = cmbDatabase.SelectedItem.ToString();
// Set the backup device to a file
BackupDeviceItem bkpDevice = new BackupDeviceItem("d:\\sana22", DeviceType.File);
// Add the backup device to the backup
bkpDatabase.Devices.Add(bkpDevice);
// Perform the backup
bkpDatabase.SqlBackup(srvSql);
//}
}
else
{
// There was no connection established; probably the Connect button was not clicked
MessageBox.Show("A connection to a SQL server was not established.", "Not Connected to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void button3_Click(object sender, EventArgs e)
{
// If there was a SQL connection created
if (srvSql != null)
{
// If the user has chosen the file from which he wants the database to be restored
// if (openBackupDialog.ShowDialog() == DialogResult.OK)
// {
// Create a new database restore operation
Restore rstDatabase = new Restore();
// Set the restore type to a database restore
rstDatabase.Action = RestoreActionType.Database;
// Set the database that we want to perform the restore on
rstDatabase.Database = cmbDatabase.SelectedItem.ToString();
// Set the backup device from which we want to restore, to a file
BackupDeviceItem bkpDevice = new BackupDeviceItem("d:\\sana22", DeviceType.File);
// Add the backup device to the restore type
rstDatabase.Devices.Add(bkpDevice);
// If the database already exists, replace it
rstDatabase.ReplaceDatabase = true;
// Perform the restore
rstDatabase.SqlRestore(srvSql);
// }
}
else
{
// There was no connection established; probably the Connect button was not clicked
MessageBox.Show("A connection to a SQL server was not established.", "Not Connected to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}]
|
|
|
|
|
Hi All,
Is it possible to make the dynamically enum,means it should be created based on the values picked from DB?
Thanks,
Lalit
|
|
|
|
|
Enums are compile time constants and can't be modified/created at run time.
|
|
|
|
|
Appartently they can be created at run time, but they'd be fairly useless as far as I can tell.
|
|
|
|
|
Try using T4
Look here[^] to get you started.
|
|
|
|
|
Not in a way that it would be any useful.
I think that you should look into how you could use a Dictionary instead.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
You can always compile an unit using CodeDOM, but I doubt it will be any useful, as it will not have any hard-coded references to it.
I also suggest using dictionaries to do the job.
|
|
|
|
|
Hi friends,
I have a small project, of which, I do not want to create any setup. Now, I have copied the project .exe file (standalone application) from Debug-Bin-project.exe and am trying to execute it on another machine which has .NET framework 2.0 and 3.5 installed. But surprisingly, I get an error message something like this: The application failed to initialize properly (000000000000..//error code..) Click Ok to terminate the application. . Can anyone explain me the reason for this. Does this mean, that what I did ain't the appropriate way of creating or running a standalone executable application? If yes, then please explain me a better way.
Your help will be truly appreciated,
Rajdeep.NET
|
|
|
|
|
Rajdeep.NET wrote: Now, I have copied the project .exe file (standalone application) from Debug-Bin-project.exe and am trying to execute it on another machine
Make sure you copy all dependent files as well, like configuration files and other assembly(not the .NET framework assemblies) references.
Rajdeep.NET wrote: The application failed to initialize properly (000000000000..//error code..) Click Ok to terminate the application.
Look in the event viewer for a detailed error message.
|
|
|
|
|
N a v a n e e t h wrote: Make sure you copy all dependent files as well, like configuration files and other assembly(not the .NET framework assemblies) references.
Hi Navaneeth,
Thanks for your help yaar, but I want to extract only the .exe file. And moreover, my clients wont be having Visual Studio.NET installed on their system. So, copying the configuration files and assemblies wont help. I've seen many applications which are standalone with just an .exe and no setup is required. Just downloading'em and running the .exe does the work. Ain't it possible in this case?
Help needed,
Rajdeep.NET
|
|
|
|
|
Did you reference any dll's? If so, those dll's have to reside on the cpu where the app will run. This also counts for any setting/configuration file.
If you use databases, does the connectionstring also count for that machine?
there could be a million other reasons why it failed.
Some suggestions:
- Add some error handling, so the user will get a clean error message on failure.
- Add some logging so you can at least find the error when it occurs.
- Read up on software development.
hope that helps.
|
|
|
|
|
Rajdeep.NET wrote: And moreover, my clients wont be having Visual Studio.NET installed on their system
VS .NET is just an editor and your client don't need to install that at all. Your client needs to install only .NET framework redistributable package. If your application is using only the framework classes, copying EXE may work.
|
|
|
|
|
If you have developed a .NET application (which by all the other questions you have posted in he last week or two seems very likely) then the target machine must have the .NET framework installed. I could be wrong, but I believe Vista has this automatically, but definately XP doesn't.
Prior to .NET (native code) EXE files do not always require more than just the EXE file.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
It's quite possible to accomplish that you need only the .exe file to run the application, but then you have to be careful not to use anything that is stored outside of it.
The configuration file is not for Visual Studio, it's for the program itself. Some controls (for example the OpenFileDialog) saves informtion in the configuration file. If you use a control that does, you either need the configuration file, or you need to change the settings of the control so that it doesn't use the file.
If you have referenced any libraries that is not in the framework, you need those .dll files along with the .exe file.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Rajdeep.NET wrote: Debug
That might be your problem. Try a release build.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
That should be fine, you must be missing something.
|
|
|
|