|
The code which i have currently written to insert the values is
try
{
string strInsert = "insert into Quotation" +
"(JobNum, NatureOfComplaint1, NatureOfComplaint2, NatureOfComplaint3)"
+ "values('" + this.txtNatureofComplaint1.Text + "','" + this.txtNatureofComplaint2.Text + "','" + this.txtNatureofComplaint3.Text + "')";
{
MySqlCommand command = new MySqlCommand(strInsert, Quotation.con);
Quotation.dQuotationAdapter.InsertCommand = command;
//Insert new record
Quotation.dQuotationAdapter.InsertCommand.ExecuteNonQuery();
MessageBox.Show("New Record Saved Successfully");
}
catch (MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
In the above code i want to insert one value for JobNum and three values for NatureofComlpaint from different text boxes. So if there are three textboxes from where i want to fetch the value and store it into a single column of NatureofComplaint then how i will do that.
It always throws an exception that value count dosent match the row count.
How can i slove this issue.
Imran
|
|
|
|
|
Hi,
Recently I have launched a service and it is working fine.
The problem now is it lapses a second for every 2 days.
Is there any workaround to solve this.
Can any one advise me on this.
Long Live
|
|
|
|
|
What do you mean? What lapses a second? What processing is going on? Without this information, I wouldn't even begin to know where to look.
|
|
|
|
|
Hi thanks for you reply.
The service generates a file on a daily basis at a specified time range mentioned in the app config file. For this purpose the service will make a check the current time against the one in config file for every 5 mins.
This part works fine. The problem is for example if it check by 12:34:33 pm the next check is performed exactly at 12:39:33 PM.
But in course of time say a day or two the checking drifts from 12:34:33 PM to 12:34:34 PM. Like this with in a month the polling time chages to 12:35:XX PM.
I wish to put a check on this. B'coz if the file generation time range is between 12:33:00 PM 12:36:00 PM in course of time the service may run without generating the file.
Thanx and Rgds,
Long Live
|
|
|
|
|
Without looking at the code, how do you expect us to help you?
*If* you are using Thread.Sleep(5 * 1000), then it will not be correct because the actual processing work takes up some time. Use a Timer instead.
Cheers,
Vikram.
"If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy
|
|
|
|
|
I suspect that what you are seeing is simply the result of an operation taking time to complete, and the timer that is doing the polling is gradually slipping as a result.
|
|
|
|
|
This is how i coded.
lDueTime = 60000;
lPeriod = 300000;
TimerCallback timerDelegate = new TimerCallback(FileOperations);
ThreadTimer = new Timer(timerDelegate, null, lDueTime, lPeriod);
public void FileOperations()
{
// My code goes here
}
Long Live
|
|
|
|
|
Hi,
in my program, I want to prepare a choice for user to make the program run when windows starts. (But not when s/he installs the program) I want to make it optional. For that I wrote (when the user checks that option):
string registryaddress = @"Software\Microsoft\Windows\CurrentVersion\Run";
RegistryKey rk = Registry.CurrentUser.OpenSubKey(registryaddress).CreateSubKey("programname");
rk.SetValue("programname",Application.ExecutablePath);
and I get a runtime error as follows :
"Unauthorized access exception " , Cannot write to the registry key...
I need help in this one, and also when the user unchecks this option , I have to delete this registry right?
But the bigger problem occurs when user checks this option but uninstalls the program after that. How can I make the C# Setup Deployement project (I mean the installer) uninstall this registry file, which had not been installed during the installation rather done by the user sometime after.
Thanks..
|
|
|
|
|
Registry.CurrentUser.OpenSubKey(registryaddress)
opens the key as a readonly key. Try
Registry.CurrentUser.OpenSubKey(registryaddress, true)
to open it with write permissions. MSDN[^]
To have the installer remove it on an un-installation, you could have the installer put the key in the registry when the program is installed; then when the installer is run to remove the program it'll automatically remove the key for you. If you want the autostart disabled by default then you could put a little check in your app that removes the key the first time it's run. It may be a little kludgy but it's just an idea
|
|
|
|
|
ok, but when I open the registry part in the setup project, tree-view on the left shows registry but narrows down only to :
H_KEY_CURRENT_USER -> Software -> [Manufacturer]
while I somehow must create the key in the following path, as we talked about earlier :
H_KEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
I'm not familiar with registry stuff so I'm stuck at this point
On the other hand, some friends said I could put a shortcut to my application's exe file into the Users Startup Folder using Setup Project.
This method seems to be working but to avoid the autostart, I shall delete this shortcut when user doesn't want so. This brings me two other problems as:
1) Startup path is
C:\Documents and Settings\[username]\Start Menu\Programs\Startup
but how can I get the username?
2) I dont even know how to make a shortcut. I only know File.Rename, File.Exists and File.Delete
I would be too glad if you help me out in either scenarios.
|
|
|
|
|
Fortunately you've got lots of options here
Option 1) In the setup project, right click on the Software registry key, select [ New -> Key ] and create a key called "Microsoft", then right click on that and add "Windows" until you get down to where you put your applications path
Option 2) Environment.SpecialFolder.Startup returns the users Startup folder. To create a windows shortcut, add a reference in your project to IWshRuntimeLibrary , then try this snippet:
IWshRuntimeLibrary.WshShell winShell = new IWshRuntimeLibrary.WshShellClass();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)winShell.CreateShortcut(pathToShortcut);
shortcut.TargetPath = pathToTarget;
shortcut.Save();
where pathToShortcut is something like Environment.SpecialFolder.Startup + "\\MyApp.lnk" and pathToTarget is the full path to your app; it's probably a good idea to throw a try { } catch (COMException) { } around it all since they're COM objects you'd be using. To remove a shortcut just use a File.Delete .
Option 3) Use a custom action. On installation, uninstallation, upgrade, rollback, etc you can define a custom executable for the installer to execute. You could create one that simply checks for the reg key when the program is removed and deletes it if it exists. Check here[^] for a tutorial.
|
|
|
|
|
this post looks veery useful! Thanks a lot!
One last thing that I have to ask before I let you go is:
Jimmanuel wrote: To create a windows shortcut, add a reference in your project to IWshRuntimeLibrary,
I couldnt find this reference in the COM tab.
Rather I have : (I thought they may be related)
Microsoft Script Control 1.0
Microsoft Scripting Runtime
Microsoft Script Scriptlet Library
But they too didnt help me use IWshRuntimeLibrary
Is it someting I have to download from internet?
I'm using Visual Studio .NET 2005 by the way
|
|
|
|
|
Sorry, it's the "Windows Script Host Object Model" in the COM tab but when it's been added to the project it's shown as IWshRuntimeLibrary
|
|
|
|
|
Man I solved the previous problem :
it was "Windows Script Host Object Model" to use and after that Library was defined and I could create a shortcut
But now I'm having trouble with "Enviroment.SpecialFolder.Startup"
when I do this one :
MessageBox.Show(System.IO.Directory.Exists(Environment.SpecialFolder.Startup.ToString())+"");
I get false? Is there something wrong ...
IWshRuntimeLibrary.WshShell winShell = new IWshRuntimeLibrary.WshShellClass();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)winShell.CreateShortcut(Environment.SpecialFolder.Startup+"\\a.lnk");
shortcut.TargetPath = "D:\\a.txt";
shortcut.Save();
This also didnt work for me It says "system couldnt find the path" for the environment part..
|
|
|
|
|
whoops I found this one too:
Environment.GetFolderPath(Environment.SpecialFolder.Startup)+"\\a.lnk"
worked..
sorry for keeping you busy, thanks a lot!!!
|
|
|
|
|
methhoo wrote: Environment.GetFolderPath
whoops, forgot that part
glad to help
|
|
|
|
|
Pls see the code that I have used for setting the registry option when the user checks that option
void startup_Click(object sender, EventArgs e)<br />
{<br />
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");<br />
if (((MenuItem)sender).Checked)<br />
{<br />
key.DeleteValue("MyApp", false);<br />
((MenuItem)sender).Checked = false; <br />
}<br />
else<br />
{<br />
key.SetValue("MyApp", Application.ExecutablePath, RegistryValueKind.String);<br />
((MenuItem)sender).Checked = true;<br />
}<br />
}
methhoo wrote: How can I make the C# Setup Deployement project
I am not sure about this..
*jaans
|
|
|
|
|
So how do you handle the situation that; user uninstalls your program , but registry is still there. I mean wouldn't it cause an error every time windows starts, unless user knows how to delete this registry file.
I wish we could trigger (may be) an exe file when uninstall procedure begins, and do whatever stuff to do, after that uninstall would also delete this worker exe.file
|
|
|
|
|
Hi,
In my dataset I have numerous table adapters which I need to chose from at runtime.
I can create at runtime a text string for the adapter I need to use however I cannot use that string to construct the method. What I have done is create an array of tableadapters and then used the index of that array to contruct the method.
As the project grows, this is becoming a consuming exercise and I am surprised there isn't a better way.
Is there some way that you can select a tableadapter from the dataset at runtime using the string representation of the table adapter to select it with.
Thanks.
|
|
|
|
|
Glen Harvy,
I THINK its possible to do this with Reflection, but i've never used it, maybe a bit of googling/someone else might be able to confirm my post.
Regards,
Gareth.
|
|
|
|
|
Thanks for your response.
I've never used reflection either! <grunt> Guess I'll have to learn
I've tried googling (always do) and I'm sure it's there but what do I search on is the hard part
Glen Harvy
|
|
|
|
|
Hi All:
I've been trying to figure out how to print multiple copies of a page. This code is as close as I've been able to come, but I get odd results. The first time I try to print I specify 2 pages and I get 4 pages. Without leaving the program, the second time I try to print I specify 2 pages and I get one page printed with the second page on top of the first.
Any thoughts you have are very much appreciated!
Dale E. Moore
using System;<br />
using System.Drawing;<br />
using System.Drawing.Printing;<br />
using System.Windows.Forms;<br />
namespace MultipleCopies<br />
{<br />
public partial class Form2 : Form<br />
{<br />
private PrintDocument printDoc = new PrintDocument();<br />
private int copiesToPrint;<br />
public Form2()<br />
{<br />
InitializeComponent();<br />
}<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); <br />
PrintDialog dlg = new PrintDialog();<br />
dlg.PrinterSettings = new PrinterSettings();<br />
if (dlg.ShowDialog() == DialogResult.OK) {<br />
copiesToPrint = dlg.PrinterSettings.Copies;<br />
printDoc.Print(); <br />
}<br />
}<br />
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e) {<br />
String textToPrint = "Printing " + copiesToPrint;<br />
Font printFont = new Font("Courier New", 12);<br />
int leftMargin = e.MarginBounds.Left;<br />
int topMargin = e.MarginBounds.Top;<br />
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, leftMargin, topMargin);<br />
copiesToPrint--;<br />
if (copiesToPrint < 1) <br />
e.HasMorePages = false;<br />
else <br />
e.HasMorePages = true;<br />
}<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.Run(new Form2());<br />
}<br />
}<br />
}
|
|
|
|
|
Shouldn't it be:
dlg.PrinterSettings.Copies = copiesToPrint;
Since you want to set the number of copies, not get the number.
Regards,
Gareth.
|
|
|
|
|
Thank you for the dialog; I fear I have been unclear in my specification! I want to print multiple copies of a multi-page document. So
printDoc.PrinterSettings.Copies = dlg.PrinterSettings.Copies; should set the copies and the number gets stuffed, but it seems to only control the first printing. And I've changed the source code, below, to identify the numberOfPages which also only seems to work on the first printing.
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace MultipleCopies
{
public partial class Form2 : Form
{
private PrintDocument printDoc = new PrintDocument();
private int numberOfPages;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
PrintDialog dlg = new PrintDialog();
dlg.PrinterSettings = new PrinterSettings();
if (dlg.ShowDialog() == DialogResult.OK) {
printDoc.PrinterSettings.Copies = dlg.PrinterSettings.Copies;
numberOfPages = 2;
printDoc.Print();
}
}
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)
{
String textToPrint = "Printing copies " + printDoc.PrinterSettings.Copies
+ ", pages " + numberOfPages;
Font printFont = new Font("Courier New", 12);
int leftMargin = e.MarginBounds.Left;
int topMargin = e.MarginBounds.Top;
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black,
leftMargin, topMargin);
numberOfPages--;
if (numberOfPages < 1)
e.HasMorePages = false;
else
e.HasMorePages = true;
}
[STAThread]
static void Main()
{
Application.Run(new Form2());
}
}
}
|
|
|
|
|
Thanks to your help I was able to blow away some of the fog in my mind and realize I should be handling my variables differently. The following code has resolved my problem.
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace MultipleCopies
{
public partial class Form2 : Form
{
private PrintDocument printDoc;
private int numberOfPages;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
printDoc = new PrintDocument();
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
PrintDialog dlg = new PrintDialog();
dlg.PrinterSettings = new PrinterSettings();
if (dlg.ShowDialog() == DialogResult.OK) {
printDoc.PrinterSettings.Copies = dlg.PrinterSettings.Copies;
numberOfPages = 2;
printDoc.Print();
}
}
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)
{
String textToPrint = "Printing copies " + printDoc.PrinterSettings.Copies
+ ", pages " + numberOfPages;
Font printFont = new Font("Courier New", 12);
int leftMargin = e.MarginBounds.Left;
int topMargin = e.MarginBounds.Top;
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black,
leftMargin, topMargin);
numberOfPages--;
if (numberOfPages < 1)
e.HasMorePages = false;
else
e.HasMorePages = true;
}
[STAThread]
static void Main()
{
Application.Run(new Form2());
}
}
}
|
|
|
|