|
The method that the post above mentions works for some but not all shortcuts (AFAIK). The preferred method is to use the KeyConverter class (in System.Windows.Forms) to do this. It does not take strings like "CtrlM", but it will take strings like "Ctrl+M" or "Ctrl+Shift+M".
|
|
|
|
|
What's the easiest way of rounding the time to the nearest five minutes in C#?
Rich.
|
|
|
|
|
There really isn't a builtin method for this. However - you can access the minutes property of the DateTime object and calculate the nearest multiple of 5.
|
|
|
|
|
Hi, is there anyone who can point or provide me with some samples of how to Select, Insert Update and delete using OLEDB in C#
Preferably a simple basic example that doesn't use stored procedure.
thanks.
|
|
|
|
|
I use something similar to this for INSERT an new record:
OleDbConnection conn = new OleDbConnection( DB_STR );
OleDbDataAdapter da = new OleDbDataAdapter( "SELECT TOP 1 * FROM Guestbook", conn );
OleDbCommandBuilder cb = new OleDbCommandBuilder( da );
cb.QuotePrefix = "[";
cb.QuoteSuffix = "]";
DataSet ds = new DataSet();
da.Fill( ds );
DataTable table = ds.Tables[0];
DataRow row = table.NewRow();
row["Date"] = DateTime.Now;
row["Name"] = name;
row["EMail"] = email;
row["Text"] = text;
table.Rows.Add( row );
da.Update( ds );
conn.Close();
And for INSERT or UPDATE :
OleDbConnection conn = new OleDbConnection( DB_STR );
OleDbDataAdapter da = new OleDbDataAdapter( "SELECT TOP 1 * FROM Guestbook WHERE ID="+ID, conn );
OleDbCommandBuilder cb = new OleDbCommandBuilder( da );
cb.QuotePrefix = "[";
cb.QuoteSuffix = "]";
DataSet ds = new DataSet();
da.Fill( ds );
DataTable table = ds.Tables[0];
if ( table.Rows.Count==0 )
{
DataRow row = table.NewRow();
row["Date"] = DateTime.Now;
row["Name"] = name;
row["EMail"] = email;
row["Text"] = text;
table.Rows.Add( row );
}
else
{
DataRow row = table.Rows[0];
row["Date"] = DateTime.Now;
row["Name"] = name;
row["EMail"] = email;
row["Text"] = text;
}
da.Update( ds );
conn.Close();
For the SELECT and DELETE I just use single-statement SQL-queries, which I format with string.Format() .
--
- Free Windows-based CMS: www.zeta-software.de/enu/producer/freeware/download.html
- See me: www.magerquark.de
|
|
|
|
|
thanks.
I got a question. what is the following code for?
<br />
cb.QuotePrefix = "[";<br />
cb.QuoteSuffix = "]";<br />
thanks =)
|
|
|
|
|
Here is my code.
HttpClientChannel channel = new HttpClientChannel();
ChannelServices.RegisterChannel(channel);
try{
url = "http://"+servername+":7777";
RemotingConfiguration.RegisterActivatedClientType(typeof(MyService), url);
MyService myservice = new MyService();
}catch(Exception){...}
If I input an error servername,I want to know error in customized timeout such as 10 seconds or else. How? Thanks!
|
|
|
|
|
If you looked at the SDK documentation for HttpClientChannel , the solution is obvious: channel.Properties.Add("timeout", timeout in milliseconds)
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Are you sure?
When I use the following code,
channel = new HttpClientChannel();
channel.Properties.Add("timeout",10000);
JIT throws System.NotSupportedException.
What is your suggestion?
|
|
|
|
|
I knew something about it. The timout is a new property that is introduced in .NET framework 1.1. I have changed my framework version to 1.1.
But when I use it like the following,
IDictionary props = new Hashtable();
props["timeout"] = 30000;
HttpClientChannel channel = new HttpClientChannel(props,
new SoadClientFormatterSinkProvider());
it seems the timeout(30 seconds) does not take effect.
Why? Could you help me ?
|
|
|
|
|
No, the "timeout" property has existed even before the release of 1.0 and the documentation backs this up (plus the fact I have MS Press's "Microsoft .NET Remoting" that was written about the time 1.0 was released and mentioned it.
As far as the timeout not working, are you sure it's the HttpClientChannel that's timing out? I just ask because we had a similar problem at work yesterday I worked on for a while where our remoting objects talk to SQL Server and communicate over HTTP since they're hosted by IIS. In that case, there were many timeouts: SQL Server's query timeout, the SqlCommand.CommandTimeout , the HttpClientChannel timeout (which worked, and we're using 1.0), and - in some cases - the ASP.NET worker process's timeout.
You can also configure the timeout as an arbitrary attribute in the <channel> section of your .config file (if you configure your remoting object via a configuration file). This makes it easy to change. See the docs for the element for more details.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
It sounds quite reasonable.Thank you!
|
|
|
|
|
I am currently working on a physics project that will use cdrom optics.
To do what (I hope) to do, I need to write data to a cd as a specific series of bits as far out to the cd's lead-out as possible and so I want to have full control of this rather than have to pfaff about with my cdrom software.
Is there a way to write to a cd from c#?
Oscar the Dog
|
|
|
|
|
Oscar Dog wrote:
Is there a way to write to a cd from c#?
You mean .NET? C# is just a language that targets the CLR. And while there probably is a way (did you actually try googling for one?), this would be insane. .NET languages are upper-level languages that typically require wrapper libraries, like the System.Windows.Forms assembly contains mostly wrappers of Windows Common Controls. Then you're bound to the constraints of the library which will probably be no better than your CDR software.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hey I am a physicist, not a programmer. I realise .NET is a lng way removed from the hardware I want to control. The only reason for considering c# is that I am a lot more comfortable with it than C++.
Yeah, I googled for one and maybe my best bet is the Nero SDK.
Thanks, I think?
|
|
|
|
|
Hiya I have made a Service program by following one of the tutorials in Code Project. It shows you how to create a service from scratch and make an installer for the service. I have ran the installer but the service does not show in the services.
I have also tried to install the service also by using install util -i myapp.exe.
I have re-read and checked that I have done everything the document says and I have.
Does anyone know y my service will not appear??
|
|
|
|
|
I've noticed a strange problem with the services MMC and that is that if you install or uninstall a service from a command prompt it doesn't update in the Services MMC.
I wonder if the problem is as simple as restarting the Services MMC?
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
|
|
|
|
|
I have 200 jpgs that originally were a single jpg. I need to tile these back (10x20) and save it out to a single jpg. Is it possible move blocks of memory around into the correct positions to reassemble the original jpg (after striping out the jpg header)?
(Basically, I’m looking for a simple (i.e. lazy) way out without having to read through the jpeg specs.)
Thanks in advance,
Kevin
|
|
|
|
|
GDI+ will read and write jpegs, so all you need to do is create an image big enough, load the smaller ones, drawn them onto it, and save it.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
|
I am new C# programmer, transferring from Mainframe COBOL. I am trying to learn the in's and out's of C# for a major project at work and am trying to figure out how to call another project's form depending on a user selection. I can get the user selection to work, but I cannot figure out how to get the new form to start. Both projects are in the same solution, if that helps. Can anyone help me please?
Thanks in advance!
Chuck Schmidt
|
|
|
|
|
Option 1:
Use the System::Diagnostics::Process class and run the .exe of the form.
Option 2:
Call ShowDialog() on the form.
|
|
|
|
|
That won't work without remoting. That executes the entry point of the application which usually calls Application.Run , but a calling app has no control over that without using remoting.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Don't think of projects - think of assemblies. Just like you create a form from the System.Windows.Forms, you do from another projects. One cool trick in VS.NET is to add a project reference as a dependency to the project that needs it. Just right-click on the project that needs a class from the other project, click Add Reference, then click the Projects tab. Double-click the project to add it and click OK to close the dialog. The great thing about this is that when you do a Debug, Release, or custom build configuration, the appropriate assembly reference is used.
To use a form in another assembly, just instantiate the class (using the fully-qualified type name (namespace + class), or add using namespace; at the top of your source file. Instantiate the form like any other.
Now, if these two projects run side-by-side (both executing individually at the same time), you'll need to use remoting. Doing what the other person mentioned won't work - you can only execute a program's entry point that way.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
That is sort of what I ended up doing. I started the project over and created the other forms I needed in the same project, instead of separate projects for each form, and then instantiated an instance of the form with the ShowDialog method to display it.
Thanks for the replies>
Chuck Schmidt
|
|
|
|